diff --git a/khatru/broadcasting.go b/khatru/broadcasting.go index 7a0dd76..ff34098 100644 --- a/khatru/broadcasting.go +++ b/khatru/broadcasting.go @@ -7,5 +7,10 @@ import ( // BroadcastEvent emits an event to all listeners whose filters' match, skipping all filters and actions // it also doesn't attempt to store the event or trigger any reactions or callbacks func (rl *Relay) BroadcastEvent(evt nostr.Event) int { - return rl.notifyListeners(evt) + return rl.notifyListeners(evt, false) +} + +// ForceBroadcastEvent is like BroadcastEvent, but it skips the PreventBroadcast hook. +func (rl *Relay) ForceBroadcastEvent(evt nostr.Event) int { + return rl.notifyListeners(evt, true) } diff --git a/khatru/handlers.go b/khatru/handlers.go index 3a2cb2c..87357ff 100644 --- a/khatru/handlers.go +++ b/khatru/handlers.go @@ -223,7 +223,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { if writeErr == nil { ok = true if !skipBroadcast { - n := srl.notifyListeners(env.Event) + n := srl.notifyListeners(env.Event, false) // the number of notified listeners matters in ephemeral events if env.Event.Kind.IsEphemeral() { diff --git a/khatru/listener.go b/khatru/listener.go index d3da7c3..579abbc 100644 --- a/khatru/listener.go +++ b/khatru/listener.go @@ -133,12 +133,12 @@ func (rl *Relay) removeClientAndListeners(ws *WebSocket) { } // returns how many listeners were notified -func (rl *Relay) notifyListeners(event nostr.Event) int { +func (rl *Relay) notifyListeners(event nostr.Event, skipPrevent bool) int { count := 0 listenersloop: for _, listener := range rl.listeners { if listener.filter.Matches(event) { - if nil != rl.PreventBroadcast { + if !skipPrevent && nil != rl.PreventBroadcast { if rl.PreventBroadcast(listener.ws, listener.filter, event) { continue listenersloop }