damus

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

commit 9b79b46601b93b36f25e501bf857c74c31b2ef81
parent 8cc3edf195a27dc35b0b350207c5ae977b466587
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 18 Apr 2022 13:17:34 -0700

better reply descriptions

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

Diffstat:
Mdamus/Nostr/NostrEvent.swift | 21++++++++++++++++++++-
Mdamus/Views/EventDetailView.swift | 4+++-
Mdamus/Views/EventView.swift | 34+++++++++++++++++++++++++++++-----
Mdamus/Views/ProfilePicView.swift | 4++--
4 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -130,7 +130,26 @@ class NostrEvent: Codable, Identifiable { public var referenced_ids: [ReferencedId] { return get_referenced_ids(key: "e") } - + + public var reply_description: ([String], Int) { + var c = 0 + var ns: [String] = [] + var i = tags.count - 1 + + while i >= 0 { + let tag = tags[i] + if tag.count >= 2 && tag[0] == "p" { + c += 1 + if ns.count < 3 { + ns.append(tag[1]) + } + } + i -= 1 + } + + return (ns, c) + } + public var referenced_pubkeys: [ReferencedId] { return get_referenced_ids(key: "p") } diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift @@ -293,7 +293,6 @@ func calculated_collapsed_events(collapsed: Bool, active: NostrEvent, events: [N let nevents = events.count var start: Int = 0 - var end: Int = 0 var i: Int = 0 return events.reduce(into: []) { (acc, ev) in @@ -306,6 +305,9 @@ func calculated_collapsed_events(collapsed: Bool, active: NostrEvent, events: [N switch highlight { case .none: + if (count == 0) { + start = 1 + } count += 1 case .main: if count != 0 { diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -50,16 +50,18 @@ struct EventView: View { ProfileName(pubkey: event.pubkey, profile: profile) Text("\(format_relative_time(event.created_at))") .foregroundColor(.gray) - if event.is_reply { - Label("", systemImage: "arrowshape.turn.up.left") - .font(.footnote) - .foregroundColor(.gray) - } Spacer() if (event.pow ?? 0) >= 10 { PowView(event.pow) } } + + if event.is_reply { + Text("\(reply_desc(profiles: profiles, event: event))") + .font(.footnote) + .foregroundColor(.gray) + .frame(maxWidth: .infinity, alignment: .leading) + } Text(event.content) .frame(maxWidth: .infinity, alignment: .leading) @@ -88,3 +90,25 @@ func format_relative_time(_ created_at: Int64) -> String { return time_ago_since(Date(timeIntervalSince1970: Double(created_at))) } + +func reply_desc(profiles: Profiles, event: NostrEvent) -> String { + let (pubkeys, n) = event.reply_description + if pubkeys.count == 0 { + return "Reply" + } + + let names: [String] = pubkeys.map { + let prof = profiles.lookup(id: $0) + return Profile.displayName(profile: prof, pubkey: $0) + } + + if names.count == 2 { + 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)" : "" + + return "Replying to \(names[0])\(and_other)" +} diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift @@ -40,14 +40,14 @@ struct ProfilePicView: View { AsyncImage(url: pic) { img in img.resizable() } placeholder: { - Color.purple.opacity(0.1) + Color.purple.opacity(0.2) } .frame(width: PFP_SIZE, height: PFP_SIZE) .clipShape(Circle()) .overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight))) .padding(2) } else { - Color.purple.opacity(0.1) + Color.purple.opacity(0.2) .frame(width: PFP_SIZE, height: PFP_SIZE) .cornerRadius(CORNER_RADIUS) .overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight)))