mirror of
https://github.com/aljazceru/khatru.git
synced 2026-02-08 22:44:21 +01:00
.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:
@@ -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()
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
1
relay.go
1
relay.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user