damus

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

commit 844146e54711876c5ff19b028abaf86d503d75ba
parent 89cb0630156a1d2566ca8826f9d279701f57d734
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 17 Apr 2022 14:37:29 -0700

fix reply tags

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

Diffstat:
Mdamus/ContentView.swift | 11+----------
Mdamus/Views/PostView.swift | 22++++++++++++++++++++++
2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -119,16 +119,7 @@ struct ContentView: View { let post = obj.object as! NostrPost print("post \(post.content)") let privkey = "" - let new_ev = NostrEvent(content: post.content, pubkey: pubkey) - for id in post.references { - var tag = [id.key, id.ref_id] - if let relay_id = id.relay_id { - tag.append(relay_id) - } - new_ev.tags.append(tag) - } - new_ev.calculate_id() - new_ev.sign(privkey: privkey) + let new_ev = post.to_event(privkey: privkey, pubkey: pubkey) self.pool?.send(.event(new_ev)) } } diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -16,6 +16,28 @@ extension Notification.Name { struct NostrPost { let content: String let references: [ReferencedId] + + public func to_event(privkey: String, pubkey: String) -> NostrEvent { + let new_ev = NostrEvent(content: content, pubkey: pubkey) + for id in references { + var tag = [id.key, id.ref_id] + if let relay_id = id.relay_id { + tag.append(relay_id) + } + new_ev.tags.append(tag) + // filter our pubkeys + new_ev.tags = new_ev.tags.filter { + if $0[0] == "p" { + return $0[1] != pubkey + } else { + return true + } + } + } + new_ev.calculate_id() + new_ev.sign(privkey: privkey) + return new_ev + } }