From 47243fdcc4c11df61566d78953a7ec6b9dccb299 Mon Sep 17 00:00:00 2001 From: kehiy Date: Thu, 19 Sep 2024 14:12:41 +0330 Subject: [PATCH] feat(event): adding more helpers. --- count_test.go | 2 +- event.go | 22 ++++++++++++++++++++++ kinds.go | 2 +- sdk/tracker.go | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/count_test.go b/count_test.go index 6f829d6..41b5900 100644 --- a/count_test.go +++ b/count_test.go @@ -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)) diff --git a/event.go b/event.go index 37bc20d..58df4c9 100644 --- a/event.go +++ b/event.go @@ -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 +} diff --git a/kinds.go b/kinds.go index ef40e9d..2523570 100644 --- a/kinds.go +++ b/kinds.go @@ -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 diff --git a/sdk/tracker.go b/sdk/tracker.go index 9b908b2..71868cc 100644 --- a/sdk/tracker.go +++ b/sdk/tracker.go @@ -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 {