damus

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

commit 5bb46c5d100e1859712e9b30accd80c8d61691a2
parent fd4aa2bb3deab874f2785a565a4442506a4aedb2
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 18 Apr 2022 17:31:39 -0700

reply bug fixes

still need to revamp this logic for mentions

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

Diffstat:
Mdamus/Nostr/NostrEvent.swift | 9+++++++--
Mdamus/Views/EventDetailView.swift | 7+++++++
Mdamus/Views/EventView.swift | 15+++++++++++----
3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -33,7 +33,7 @@ struct EventId: Identifiable, CustomStringConvertible { } } -class NostrEvent: Codable, Identifiable { +class NostrEvent: Codable, Identifiable, CustomStringConvertible { var id: String var sig: String var tags: [[String]] @@ -48,6 +48,11 @@ class NostrEvent: Codable, Identifiable { let created_at: Int64 let kind: Int let content: String + + var description: String { + let p = pow.map { String($0) } ?? "?" + return "NostrEvent { id: \(id) pubkey \(pubkey) kind \(kind) tags \(tags) pow \(p) content '\(content)' }" + } private enum CodingKeys: String, CodingKey { case id, sig, tags, pubkey, created_at, kind, content @@ -140,7 +145,7 @@ class NostrEvent: Codable, Identifiable { let tag = tags[i] if tag.count >= 2 && tag[0] == "p" { c += 1 - if ns.count < 3 { + if ns.count < 2 { ns.append(tag[1]) } } diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift @@ -120,6 +120,7 @@ struct EventDetailView: View { scroll_to_event(scroller: proxy, id: ev.id, delay: 0.5, animate: true) } .onTapGesture { + print_event(ev) let any = any_collapsed(collapsed_events) if (collapsed && any) || (!collapsed && !any) { toggle_collapse_thread(scroller: proxy, id: ev.id) @@ -129,6 +130,7 @@ struct EventDetailView: View { if !(self.collapsed && highlight.is_none) { EventView(event: ev, highlight: collapsed ? .none : highlight, has_action_bar: true) .onTapGesture { + print_event(ev) if !collapsed { toggle_collapse_thread(scroller: proxy, id: ev.id) } @@ -354,3 +356,8 @@ func any_collapsed(_ evs: [CollapsedEvent]) -> Bool { } return false } + + +func print_event(_ ev: NostrEvent) { + print(ev.description) +} diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -103,12 +103,19 @@ func reply_desc(profiles: Profiles, event: NostrEvent) -> String { } if names.count == 2 { + if n > 2 { + let and_other = reply_others_desc(n: n, n_pubkeys: pubkeys.count) + return "Replying to \(names[0]), \(names[1])\(and_other)" + } return "Replying to \(names[0]) & \(names[1])" } - let other = n - pubkeys.count - let plural = other == 1 ? "" : "s" - let and_other = n > 1 ? " & \(other) other\(plural)" : "" - + let and_other = reply_others_desc(n: n, n_pubkeys: pubkeys.count) return "Replying to \(names[0])\(and_other)" } + +func reply_others_desc(n: Int, n_pubkeys: Int) -> String { + let other = n - n_pubkeys + let plural = other == 1 ? "" : "s" + return n > 1 ? " & \(other) other\(plural)" : "" +}