Skip to content

Commit

Permalink
policies: RestrictToSpecifiedKinds() to allow ephemeral.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Oct 22, 2024
1 parent 8f62b2f commit 902e882
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion policies/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""
}
Expand Down

0 comments on commit 902e882

Please sign in to comment.