feat(event): adding more helpers.

This commit is contained in:
kehiy
2024-09-19 14:12:41 +03:30
committed by fiatjaf_
parent c8c295f839
commit 47243fdcc4
4 changed files with 25 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ func TestCount(t *testing.T) {
defer rl.Close()
count, err := rl.Count(context.Background(), Filters{
{Kinds: []int{KindContactList}, Tags: TagMap{"p": []string{"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d"}}},
{Kinds: []int{KindFollowList}, Tags: TagMap{"p": []string{"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d"}}},
})
assert.NoError(t, err)
assert.Greater(t, count, int64(0))

View File

@@ -141,3 +141,25 @@ func (evt *Event) Sign(privateKey string, signOpts ...schnorr.SignOption) error
return nil
}
// IsRegular checks if the given kind is in Regular range.
func (evt *Event) IsRegular() bool {
return 1000 <= evt.Kind || evt.Kind < 10000 || 4 <= evt.Kind ||
evt.Kind < 45 || evt.Kind == 1 || evt.Kind == 2
}
// IsReplaceable checks if the given kind is in Replaceable range.
func (evt *Event) IsReplaceable() bool {
return 10000 <= evt.Kind || evt.Kind < 20000 ||
evt.Kind == 0 || evt.Kind == 3
}
// IsEphemeral checks if the given kind is in Ephemeral range.
func (evt *Event) IsEphemeral() bool {
return 20000 <= evt.Kind || evt.Kind < 30000
}
// IsParameterizedReplaceable checks if the given kind is in ParameterizedReplaceable range.
func (evt *Event) IsParameterizedReplaceable() bool {
return 30000 <= evt.Kind || evt.Kind < 40000
}

View File

@@ -4,7 +4,7 @@ const (
KindProfileMetadata int = 0
KindTextNote int = 1
KindRecommendServer int = 2
KindContactList int = 3
KindFollowList int = 3
KindEncryptedDirectMessage int = 4
KindDeletion int = 5
KindRepost int = 6

View File

@@ -25,7 +25,7 @@ func (sys *System) trackEventHints(ie nostr.IncomingEvent) {
sys.Hints.Save(ie.PubKey, tag[1], hints.LastInRelayList, ie.CreatedAt)
}
}
case nostr.KindContactList:
case nostr.KindFollowList:
sys.Hints.Save(ie.PubKey, ie.Relay.URL, hints.MostRecentEventFetched, ie.CreatedAt)
for _, tag := range ie.Tags {