mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-08 20:21:43 +02:00
support prefix search for ids and authors (nip01 update).
This commit is contained in:
@@ -29,7 +29,7 @@ func (ef Filter) Matches(event *Event) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ef.IDs != nil && !ef.IDs.Contains(event.ID) {
|
if ef.IDs != nil && !ef.IDs.ContainsPrefixOf(event.ID) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ func (ef Filter) Matches(event *Event) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ef.Authors != nil && !ef.Authors.Contains(event.PubKey) {
|
if ef.Authors != nil && !ef.Authors.ContainsPrefixOf(event.PubKey) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,6 +62,15 @@ func (haystack StringList) Contains(needle string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (haystack StringList) ContainsPrefixOf(needle string) bool {
|
||||||
|
for _, hay := range haystack {
|
||||||
|
if strings.HasPrefix(needle, hay) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (haystack IntList) Contains(needle int) bool {
|
func (haystack IntList) Contains(needle int) bool {
|
||||||
for _, hay := range haystack {
|
for _, hay := range haystack {
|
||||||
if hay == needle {
|
if hay == needle {
|
||||||
|
Reference in New Issue
Block a user