Browse Source

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
translations_damus-localizations-en-us-xcloc-localized-contents-en-us-xliff--master_es_419
William Casarin 2 years ago
parent
commit
00c819140b
  1. 15
      damus/Models/HomeModel.swift

15
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
}

Loading…
Cancel
Save