OverwriteResponseEvent for optionally modifying events before sending them to client.

This commit is contained in:
fiatjaf
2023-11-04 17:35:47 -03:00
parent 80586c4573
commit 5f79b883cb
3 changed files with 8 additions and 0 deletions

View File

@@ -86,7 +86,11 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
}
}
for _, ovw := range rl.OverwriteResponseEvent {
ovw(ctx, evt)
}
notifyListeners(evt)
return nil
}

View File

@@ -236,6 +236,9 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
go func(ch chan *nostr.Event) {
for event := range ch {
for _, ovw := range rl.OverwriteResponseEvent {
ovw(ctx, event)
}
ws.WriteJSON(nostr.EventEnvelope{SubscriptionID: &id, Event: *event})
}
eose.Done()

View File

@@ -45,6 +45,7 @@ type Relay struct {
RejectFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
RejectCountFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
OverwriteDeletionOutcome []func(ctx context.Context, target *nostr.Event, deletion *nostr.Event) (acceptDeletion bool, msg string)
OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event)
StoreEvent []func(ctx context.Context, event *nostr.Event) error
DeleteEvent []func(ctx context.Context, event *nostr.Event) error
QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error)