a bunch of [32]byte conversions. still more needed.

This commit is contained in:
fiatjaf
2025-04-14 17:31:23 -03:00
parent 40535e6b19
commit b4268d649c
132 changed files with 857 additions and 879 deletions
+19 -32
View File
@@ -6,12 +6,10 @@ import (
"github.com/mailru/easyjson"
)
type Filters []Filter
type Filter struct {
IDs []string
Kinds []int
Authors []string
IDs []ID
Kinds []uint16
Authors []PubKey
Tags TagMap
Since *Timestamp
Until *Timestamp
@@ -24,29 +22,6 @@ type Filter struct {
type TagMap map[string][]string
func (eff Filters) String() string {
j, _ := json.Marshal(eff)
return string(j)
}
func (eff Filters) Match(event *Event) bool {
for _, filter := range eff {
if filter.Matches(event) {
return true
}
}
return false
}
func (eff Filters) MatchIgnoringTimestampConstraints(event *Event) bool {
for _, filter := range eff {
if filter.MatchesIgnoringTimestampConstraints(event) {
return true
}
}
return false
}
func (ef Filter) String() string {
j, _ := easyjson.Marshal(ef)
return string(j)
@@ -99,11 +74,11 @@ func FilterEqual(a Filter, b Filter) bool {
return false
}
if !similar(a.IDs, b.IDs) {
if !similarID(a.IDs, b.IDs) {
return false
}
if !similar(a.Authors, b.Authors) {
if !similarPublicKey(a.Authors, b.Authors) {
return false
}
@@ -142,14 +117,26 @@ func FilterEqual(a Filter, b Filter) bool {
func (ef Filter) Clone() Filter {
clone := Filter{
IDs: slices.Clone(ef.IDs),
Authors: slices.Clone(ef.Authors),
Kinds: slices.Clone(ef.Kinds),
Limit: ef.Limit,
Search: ef.Search,
LimitZero: ef.LimitZero,
}
if ef.IDs != nil {
clone.IDs = make([]ID, len(ef.IDs))
for i, src := range ef.IDs {
copy(clone.IDs[i][:], src[:])
}
}
if ef.Authors != nil {
clone.Authors = make([]PubKey, len(ef.Authors))
for i, src := range ef.Authors {
copy(clone.Authors[i][:], src[:])
}
}
if ef.Tags != nil {
clone.Tags = make(TagMap, len(ef.Tags))
for k, v := range ef.Tags {