From 00c819140b6f96e0fb4d4574f5a7f39eb4323cb8 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sun, 15 Jan 2023 12:53:37 -0800 Subject: [PATCH] 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 --- damus/Models/HomeModel.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index 9a0901d9..91a774e1 100644 --- 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: ¬ifications, 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 +}