commit 7bf9f622552fcaf51d11616884dfc0c2c02fba0e
parent 1ba5b64df6a9f62dc3dc487271fe11d41d82b577
Author: William Casarin <jb55@jb55.com>
Date: Mon, 20 Jun 2022 15:30:14 -0700
fix home feed
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift
@@ -214,10 +214,15 @@ func is_friend_event(_ ev: NostrEvent, our_pubkey: String, contacts: Contacts) -
return true
}
- let pks = ev.referenced_pubkeys
+ let pks = get_referenced_id_set(tags: ev.tags, key: "p")
+
+ // reply to self
+ if pks.count == 0 {
+ return true
+ }
// allow reply-to-self-or-friend case
- if pks.count == 1 && contacts.is_friend(pks[0].ref_id) {
+ if pks.count == 1 && contacts.is_friend(pks.first!.ref_id) {
return true
}
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -19,7 +19,7 @@ struct KeyEvent {
let relay_url: String
}
-struct ReferencedId: Identifiable {
+struct ReferencedId: Identifiable, Hashable {
let ref_id: String
let relay_id: String?
let key: String
@@ -364,6 +364,18 @@ func get_referenced_ids(tags: [[String]], key: String) -> [ReferencedId] {
}
}
+func get_referenced_id_set(tags: [[String]], key: String) -> Set<ReferencedId> {
+ return tags.reduce(into: Set()) { (acc, tag) in
+ if tag.count >= 2 && tag[0] == key {
+ var relay_id: String? = nil
+ if tag.count >= 3 {
+ relay_id = tag[2]
+ }
+ acc.insert(ReferencedId(ref_id: tag[1], relay_id: relay_id, key: key))
+ }
+ }
+}
+
func make_first_contact_event(keypair: Keypair) -> NostrEvent? {
guard let privkey = keypair.privkey else {
return nil