From 902e882d97260e1e81218c0e8f83167c687f4ef2 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 22 Oct 2024 13:32:24 -0300 Subject: [PATCH] policies: RestrictToSpecifiedKinds() to allow ephemeral. --- policies/events.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/policies/events.go b/policies/events.go index aa2019b..f084a2c 100644 --- a/policies/events.go +++ b/policies/events.go @@ -67,11 +67,15 @@ func PreventLargeTags(maxTagValueLen int) func(context.Context, *nostr.Event) (b // RestrictToSpecifiedKinds returns a function that can be used as a RejectFilter that will reject // any events with kinds different than the specified ones. -func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Event) (bool, string) { +func RestrictToSpecifiedKinds(allowEphemeral bool, kinds ...uint16) func(context.Context, *nostr.Event) (bool, string) { // sort the kinds in increasing order slices.Sort(kinds) return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { + if allowEphemeral && event.IsEphemeral() { + return false, "" + } + if _, allowed := slices.BinarySearch(kinds, uint16(event.Kind)); allowed { return false, "" }