.PreventBroadcast slice of functions for controlling what events get broadcasted and to whom.

addresses https://t.me/nip29_temp/303
This commit is contained in:
fiatjaf
2024-07-31 10:34:44 -03:00
parent a63dc829df
commit 5f0f9eec99
3 changed files with 7 additions and 1 deletions

View File

@@ -205,7 +205,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
ovw(ctx, &env.Event)
}
if !skipBroadcast {
srl.notifyListeners(&env.Event)
srl.notifyListeners(&env.Event, nil)
}
} else {
reason = writeErr.Error()

View File

@@ -86,6 +86,11 @@ func (rl *Relay) removeListenerId(ws *WebSocket, id string) {
func (rl *Relay) notifyListeners(event *nostr.Event) {
for _, listener := range rl.listeners {
if listener.filter.Matches(event) {
for _, pb := range rl.PreventBroadcast {
if pb(listener.ws, event) {
return
}
}
listener.ws.WriteJSON(nostr.EventEnvelope{SubscriptionID: &listener.subscriptionId, Event: *event})
}
}

View File

@@ -64,6 +64,7 @@ type Relay struct {
OnDisconnect []func(ctx context.Context)
OverwriteRelayInformation []func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument
OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event)
PreventBroadcast []func(ws *WebSocket, event *nostr.Event) bool
// these are used when this relays acts as a router
routes []Route