.Until filter attr and filter.Equal() function.

This commit is contained in:
fiatjaf 2021-12-26 07:02:38 -03:00
parent 0a60285e30
commit 18ed9cd418

View File

@ -11,6 +11,7 @@ type EventFilter struct {
TagEvent string `json:"#e,omitempty"`
TagProfile string `json:"#p,omitempty"`
Since uint32 `json:"since,omitempty"`
Until uint32 `json:"until,omitempty"`
}
func (eff EventFilters) Match(event *event.Event) bool {
@ -111,5 +112,49 @@ func (ef EventFilter) Matches(event *event.Event) bool {
return false
}
if ef.Until != 0 && event.CreatedAt > ef.Until {
return false
}
return true
}
func Equal(a EventFilter, b EventFilter) bool {
if a.Kind == nil && b.Kind != nil ||
a.Kind != nil && b.Kind == nil ||
a.Kind != b.Kind {
return false
}
if a.ID != b.ID {
return false
}
if len(a.Authors) != len(b.Authors) {
return false
}
for i, _ := range a.Authors {
if a.Authors[i] != b.Authors[i] {
return false
}
}
if a.TagEvent != b.TagEvent {
return false
}
if a.TagProfile != b.TagProfile {
return false
}
if a.Since != b.Since {
return false
}
if a.Until != b.Until {
return false
}
return true
}