move everything to the same directory.

This commit is contained in:
fiatjaf
2022-01-02 08:44:18 -03:00
parent 44604e406b
commit d131e8460e
10 changed files with 192 additions and 196 deletions

90
filter.go Normal file
View File

@@ -0,0 +1,90 @@
package nostr
type EventFilters []EventFilter
type EventFilter struct {
IDs StringList `json:"ids,omitempty"`
Kinds IntList `json:"kinds,omitempty"`
Authors StringList `json:"authors,omitempty"`
Since uint32 `json:"since,omitempty"`
Until uint32 `json:"until,omitempty"`
TagE StringList `json:"#e,omitempty"`
TagP StringList `json:"#p,omitempty"`
}
func (eff EventFilters) Match(event *Event) bool {
for _, filter := range eff {
if filter.Matches(event) {
return true
}
}
return false
}
func (ef EventFilter) Matches(event *Event) bool {
if event == nil {
return false
}
if ef.IDs != nil && !ef.IDs.Contains(event.ID) {
return false
}
if ef.Kinds != nil && !ef.Kinds.Contains(event.Kind) {
return false
}
if ef.Authors != nil && !ef.Authors.Contains(event.PubKey) {
return false
}
if ef.TagE != nil && !event.Tags.ContainsAny("e", ef.TagE) {
return false
}
if ef.TagP != nil && !event.Tags.ContainsAny("p", ef.TagP) {
return false
}
if ef.Since != 0 && event.CreatedAt < ef.Since {
return false
}
if ef.Until != 0 && event.CreatedAt >= ef.Until {
return false
}
return true
}
func Equal(a EventFilter, b EventFilter) bool {
if !a.Kinds.Equals(b.Kinds) {
return false
}
if !a.IDs.Equals(b.IDs) {
return false
}
if !a.Authors.Equals(b.Authors) {
return false
}
if !a.TagE.Equals(b.TagE) {
return false
}
if !a.TagP.Equals(b.TagP) {
return false
}
if a.Since != b.Since {
return false
}
if a.Until != b.Until {
return false
}
return true
}