diff --git a/sdk/event_relays.go b/sdk/event_relays.go index 2d85ef5..5423c1e 100644 --- a/sdk/event_relays.go +++ b/sdk/event_relays.go @@ -64,7 +64,7 @@ func decodeRelayList(data []byte) []string { return relays } -func (sys *System) trackEventRelayCommon(eventID string, relay string, onlyIfItExists bool) { +func (sys *System) trackEventRelay(eventID string, relay string, onlyIfItExists bool) { // decode the event ID hex into bytes idBytes, err := hex.DecodeString(eventID) if err != nil || len(idBytes) < 8 { diff --git a/sdk/tracker.go b/sdk/tracker.go index 4d8fae6..28c198f 100644 --- a/sdk/tracker.go +++ b/sdk/tracker.go @@ -20,6 +20,8 @@ func (sys *System) TrackQueryAttempts(relay string, author string, kind int) { sys.Hints.Save(author, relay, hints.LastFetchAttempt, nostr.Now()) } +// TrackEventHintsAndRelays is meant to be as an argument to WithEventMiddleware() when you're interested +// in tracking relays associated to event ids as well as feeding hints to the HintsDB. func (sys *System) TrackEventHintsAndRelays(ie nostr.RelayEvent) { if IsVirtualRelay(ie.Relay.URL) { return @@ -29,9 +31,26 @@ func (sys *System) TrackEventHintsAndRelays(ie nostr.RelayEvent) { } if ie.Kind != 0 && ie.Kind != 10002 { - sys.trackEventRelayCommon(ie.ID, ie.Relay.URL, false) + sys.trackEventRelay(ie.ID, ie.Relay.URL, false) } + sys.trackEventHints(ie) +} + +// TrackEventHints is meant to be used standalone as an argument to WithEventMiddleware() when you're not interested +// in tracking relays associated to event ids. +func (sys *System) TrackEventHints(ie nostr.RelayEvent) { + if IsVirtualRelay(ie.Relay.URL) { + return + } + if ie.Kind < 30000 && ie.Kind >= 20000 { + return + } + + sys.trackEventHints(ie) +} + +func (sys *System) trackEventHints(ie nostr.RelayEvent) { switch ie.Kind { case nostr.KindProfileMetadata: // this could be anywhere so it doesn't count @@ -113,9 +132,10 @@ func (sys *System) TrackEventHintsAndRelays(ie nostr.RelayEvent) { } } +// TrackEventRelaysD is a companion to TrackEventRelays meant to be used with WithDuplicateMiddleware() func (sys *System) TrackEventRelaysD(relay, id string) { if IsVirtualRelay(relay) { return } - sys.trackEventRelayCommon(id, relay, true /* we pass this flag so we'll skip creating entries for events that didn't pass the checks on the function above -- i.e. ephemeral events */) + sys.trackEventRelay(id, relay, true /* we pass this flag so we'll skip creating entries for events that didn't pass the checks on the function above -- i.e. ephemeral events */) }