mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-08 23:31:41 +02:00
sdk: clarify event tracker functions.
This commit is contained in:
@ -64,7 +64,7 @@ func decodeRelayList(data []byte) []string {
|
|||||||
return relays
|
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
|
// decode the event ID hex into bytes
|
||||||
idBytes, err := hex.DecodeString(eventID)
|
idBytes, err := hex.DecodeString(eventID)
|
||||||
if err != nil || len(idBytes) < 8 {
|
if err != nil || len(idBytes) < 8 {
|
||||||
|
@ -20,6 +20,8 @@ func (sys *System) TrackQueryAttempts(relay string, author string, kind int) {
|
|||||||
sys.Hints.Save(author, relay, hints.LastFetchAttempt, nostr.Now())
|
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) {
|
func (sys *System) TrackEventHintsAndRelays(ie nostr.RelayEvent) {
|
||||||
if IsVirtualRelay(ie.Relay.URL) {
|
if IsVirtualRelay(ie.Relay.URL) {
|
||||||
return
|
return
|
||||||
@ -29,9 +31,26 @@ func (sys *System) TrackEventHintsAndRelays(ie nostr.RelayEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ie.Kind != 0 && ie.Kind != 10002 {
|
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 {
|
switch ie.Kind {
|
||||||
case nostr.KindProfileMetadata:
|
case nostr.KindProfileMetadata:
|
||||||
// this could be anywhere so it doesn't count
|
// 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) {
|
func (sys *System) TrackEventRelaysD(relay, id string) {
|
||||||
if IsVirtualRelay(relay) {
|
if IsVirtualRelay(relay) {
|
||||||
return
|
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 */)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user