better reply descriptions

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-18 13:17:34 -07:00
parent 8cc3edf195
commit 9b79b46601
4 changed files with 54 additions and 9 deletions

View File

@@ -131,6 +131,25 @@ class NostrEvent: Codable, Identifiable {
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")
}

View File

@@ -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 {

View File

@@ -50,17 +50,19 @@ 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)
.textSelection(.enabled)
@@ -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)"
}

View File

@@ -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)))