mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-28 18:51:52 +01:00
policies that remove elements from the query should just cancel the query if they remove everything.
This commit is contained in:
parent
eb83307005
commit
e9bcad8614
@ -45,7 +45,10 @@ func NoSearchQueries(ctx context.Context, filter nostr.Filter) (reject bool, msg
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RemoveSearchQueries(ctx context.Context, filter *nostr.Filter) {
|
func RemoveSearchQueries(ctx context.Context, filter *nostr.Filter) {
|
||||||
filter.Search = ""
|
if filter.Search != "" {
|
||||||
|
filter.Search = ""
|
||||||
|
filter.Limit = -1 // signals that this query should be just skipped
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveAllButKinds(kinds ...uint16) func(context.Context, *nostr.Filter) {
|
func RemoveAllButKinds(kinds ...uint16) func(context.Context, *nostr.Filter) {
|
||||||
@ -58,15 +61,23 @@ func RemoveAllButKinds(kinds ...uint16) func(context.Context, *nostr.Filter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
filter.Kinds = newKinds
|
filter.Kinds = newKinds
|
||||||
|
if len(filter.Kinds) == 0 {
|
||||||
|
filter.Limit = -1 // signals that this query should be just skipped
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveAllButTags(tagNames ...string) func(context.Context, *nostr.Filter) {
|
func RemoveAllButTags(tagNames ...string) func(context.Context, *nostr.Filter) {
|
||||||
return func(ctx context.Context, filter *nostr.Filter) {
|
return func(ctx context.Context, filter *nostr.Filter) {
|
||||||
for tagName := range filter.Tags {
|
if n := len(filter.Tags); n > 0 {
|
||||||
if !slices.Contains(tagNames, tagName) {
|
for tagName := range filter.Tags {
|
||||||
delete(filter.Tags, tagName)
|
if !slices.Contains(tagNames, tagName) {
|
||||||
|
delete(filter.Tags, tagName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(filter.Tags) == 0 {
|
||||||
|
filter.Limit = -1 // signals that this query should be just skipped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user