damus

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

commit 00dde48f97870c40aa1390a43d3b38e2a65ed5ce
parent b72fb8ba3182ab6e2e70cd9062023142bedc93e7
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 15 May 2022 13:46:48 -0700

generalize is_friend_event even further

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/ContentView.swift | 27+--------------------------
Mdamus/Models/Contacts.swift | 25+++++++++++++++++++++++++
2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -340,7 +340,7 @@ struct ContentView: View { } func is_friend_event(_ ev: NostrEvent) -> Bool { - return damus.is_friend_event(ev, our_pubkey: self.pubkey, contacts: self.damus_state!.contacts) + return damus.is_friend_event(ev, our_pubkey: self.pubkey, friends: self.damus_state!.contacts.friends) } func switch_timeline(_ timeline: Timeline) { @@ -775,28 +775,3 @@ func update_filters_with_since(last_of_kind: [Int: NostrEvent], filters: [NostrF } } - -func is_friend_event(_ ev: NostrEvent, our_pubkey: String, contacts: Contacts) -> Bool -{ - if ev.pubkey == our_pubkey { - return true - } - - if contacts.is_friend(ev.pubkey) { - return true - } - - if ev.is_reply { - // show our replies? - if ev.pubkey == our_pubkey { - return true - } - for pk in ev.referenced_pubkeys { - if contacts.is_friend(pk.ref_id) { - return true - } - } - } - - return false -} diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift @@ -120,3 +120,28 @@ func make_contact_relays(_ relays: [RelayDescriptor]) -> [String: RelayInfo] { } } + +func is_friend_event(_ ev: NostrEvent, our_pubkey: String, friends: Set<String>) -> Bool +{ + if ev.pubkey == our_pubkey { + return true + } + + if friends.contains(ev.pubkey) { + return true + } + + if ev.is_reply { + // show our replies? + if ev.pubkey == our_pubkey { + return true + } + for pk in ev.referenced_pubkeys { + if friends.contains(pk.ref_id) { + return true + } + } + } + + return false +}