mirror of
https://github.com/fiatjaf/khatru.git
synced 2026-06-12 07:38:35 +02:00
do not notify listeners when a duplicated event is received.
This commit is contained in:
18
adding.go
18
adding.go
@@ -10,17 +10,17 @@ import (
|
||||
)
|
||||
|
||||
// AddEvent sends an event through then normal add pipeline, as if it was received from a websocket.
|
||||
func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) (skipBroadcast bool, writeError error) {
|
||||
if evt == nil {
|
||||
return errors.New("error: event is nil")
|
||||
return false, errors.New("error: event is nil")
|
||||
}
|
||||
|
||||
for _, reject := range rl.RejectEvent {
|
||||
if reject, msg := reject(ctx, evt); reject {
|
||||
if msg == "" {
|
||||
return errors.New("blocked: no reason")
|
||||
return false, errors.New("blocked: no reason")
|
||||
} else {
|
||||
return errors.New(nostr.NormalizeOKMessage(msg, "blocked"))
|
||||
return false, errors.New(nostr.NormalizeOKMessage(msg, "blocked"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
}
|
||||
for range ch {
|
||||
// if we run this it means we already have this event, so we just return a success and exit
|
||||
return nil
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
// parameterized replaceable event, delete before storing
|
||||
d := evt.Tags.GetFirst([]string{"d", ""})
|
||||
if d == nil {
|
||||
return fmt.Errorf("invalid: missing 'd' tag on parameterized replaceable event")
|
||||
return false, fmt.Errorf("invalid: missing 'd' tag on parameterized replaceable event")
|
||||
}
|
||||
|
||||
filter := nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{(*d)[1]}}}
|
||||
@@ -91,9 +91,9 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
if saveErr := store(ctx, evt); saveErr != nil {
|
||||
switch saveErr {
|
||||
case eventstore.ErrDupEvent:
|
||||
return nil
|
||||
return true, nil
|
||||
default:
|
||||
return fmt.Errorf(nostr.NormalizeOKMessage(saveErr.Error(), "error"))
|
||||
return false, fmt.Errorf(nostr.NormalizeOKMessage(saveErr.Error(), "error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,5 +103,5 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user