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