diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift index 39c59d7a..d81bb34a 100644 --- 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 index c67e17a5..69838b04 100644 --- 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 index aca41be2..24d9895a 100644 --- 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 index 4cda5aff..e84a25be 100644 --- 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)))