it never ends.
This commit is contained in:
38
eventstore/wrappers/publisher.go
Normal file
38
eventstore/wrappers/publisher.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package wrappers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
"fiatjaf.com/nostr/eventstore"
|
||||
)
|
||||
|
||||
var _ nostr.Publisher = StorePublisher{}
|
||||
|
||||
type StorePublisher struct {
|
||||
eventstore.Store
|
||||
}
|
||||
|
||||
func (w StorePublisher) Publish(ctx context.Context, evt nostr.Event) error {
|
||||
if nostr.IsEphemeralKind(evt.Kind) {
|
||||
// do not store ephemeral events
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
if nostr.IsRegularKind(evt.Kind) {
|
||||
// regular events are just saved directly
|
||||
if err := w.SaveEvent(evt); err != nil && err != eventstore.ErrDupEvent {
|
||||
return fmt.Errorf("failed to save: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// others are replaced
|
||||
w.Store.ReplaceEvent(evt)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user