damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 00c819140b6f96e0fb4d4574f5a7f39eb4323cb8
parent cbc3c46c9d554c8829dc7ca9a9ffac48ffbcc3a1
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 15 Jan 2023 12:53:37 -0800

Don't include garbage in notifications

Check to make sure we have our pubkey on events coming into
notifications. Sometimes relays are buggy.

Changelog-Fixed: Don't add events to notifications from buggy relays

Diffstat:
Mdamus/Models/HomeModel.swift | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -348,6 +348,10 @@ class HomeModel: ObservableObject { } func handle_notification(ev: NostrEvent) { + guard event_has_our_pubkey(ev, our_pubkey: self.damus_state.pubkey) else { + return + } + if !insert_uniq_sorted_event(events: &notifications, new_ev: ev, cmp: { $0.created_at > $1.created_at }) { return } @@ -671,3 +675,14 @@ func handle_last_events(new_events: NewEventsBits, ev: NostrEvent, timeline: Tim return nil } + +/// Sometimes we get garbage in our notifications. Ensure we have our pubkey on this event +func event_has_our_pubkey(_ ev: NostrEvent, our_pubkey: String) -> Bool { + for tag in ev.tags { + if tag.count >= 2 && tag[0] == "p" && tag[1] == our_pubkey { + return true + } + } + + return false +}