mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-26 03:49:01 +02:00
alias TagMap to map[string]StringList.
This commit is contained in:
@@ -12,9 +12,11 @@ type Filter struct {
|
||||
Authors StringList
|
||||
Since *time.Time
|
||||
Until *time.Time
|
||||
Tags map[string]StringList
|
||||
Tags TagMap
|
||||
}
|
||||
|
||||
type TagMap map[string]StringList
|
||||
|
||||
func (eff Filters) Match(event *Event) bool {
|
||||
for _, filter := range eff {
|
||||
if filter.Matches(event) {
|
||||
|
@@ -20,7 +20,7 @@ func (f *Filter) UnmarshalJSON(payload []byte) error {
|
||||
return fmt.Errorf("filter is not an object")
|
||||
}
|
||||
|
||||
f.Tags = make(map[string]StringList)
|
||||
f.Tags = make(TagMap)
|
||||
|
||||
var visiterr error
|
||||
obj.Visit(func(k []byte, v *fastjson.Value) {
|
||||
|
@@ -26,7 +26,7 @@ func TestFilterMarshal(t *testing.T) {
|
||||
|
||||
filterj, err := json.Marshal(Filter{
|
||||
Kinds: IntList{1, 2, 4},
|
||||
Tags: map[string]StringList{"fruit": {"banana", "mango"}},
|
||||
Tags: TagMap{"fruit": {"banana", "mango"}},
|
||||
Until: &tm,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -50,7 +50,7 @@ func TestFilterMatching(t *testing.T) {
|
||||
|
||||
if !(Filter{
|
||||
Kinds: IntList{4, 5},
|
||||
Tags: map[string]StringList{
|
||||
Tags: TagMap{
|
||||
"p": {"ooo"},
|
||||
},
|
||||
IDs: StringList{"prefix"},
|
||||
@@ -72,8 +72,8 @@ func TestFilterEquality(t *testing.T) {
|
||||
}
|
||||
|
||||
if !FilterEqual(
|
||||
Filter{Kinds: IntList{4, 5}, Tags: map[string]StringList{"letter": {"a", "b"}}},
|
||||
Filter{Kinds: IntList{4, 5}, Tags: map[string]StringList{"letter": {"b", "a"}}},
|
||||
Filter{Kinds: IntList{4, 5}, Tags: TagMap{"letter": {"a", "b"}}},
|
||||
Filter{Kinds: IntList{4, 5}, Tags: TagMap{"letter": {"b", "a"}}},
|
||||
) {
|
||||
t.Error("kind+tags filters should be equal")
|
||||
}
|
||||
@@ -82,13 +82,13 @@ func TestFilterEquality(t *testing.T) {
|
||||
if !FilterEqual(
|
||||
Filter{
|
||||
Kinds: IntList{4, 5},
|
||||
Tags: map[string]StringList{"letter": {"a", "b"}, "fruit": {"banana"}},
|
||||
Tags: TagMap{"letter": {"a", "b"}, "fruit": {"banana"}},
|
||||
Since: &tm,
|
||||
IDs: StringList{"aaaa", "bbbb"},
|
||||
},
|
||||
Filter{
|
||||
Kinds: IntList{5, 4},
|
||||
Tags: map[string]StringList{"letter": {"a", "b"}, "fruit": {"banana"}},
|
||||
Tags: TagMap{"letter": {"a", "b"}, "fruit": {"banana"}},
|
||||
Since: &tm,
|
||||
IDs: StringList{"aaaa", "bbbb"},
|
||||
},
|
||||
|
Reference in New Issue
Block a user