damus

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

commit f2265153fac51c98889be6e7121b0a3278cdda13
parent b3588b9d610ae70943d6d66f12c39594cd06a00c
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 18 Apr 2022 14:53:10 -0700

determine highlight from reply map

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

Diffstat:
Mdamus/Views/EventDetailView.swift | 27++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift @@ -261,10 +261,19 @@ func make_reply_map(active: NostrEvent, events: [NostrEvent]) -> [String: ()] return is_reply } -func determine_highlight(current: NostrEvent, active: NostrEvent) -> Highlight +func determine_highlight(reply_map: [String: ()], current: NostrEvent, active: NostrEvent) -> Highlight { if current.id == active.id { return .main + } else if reply_map[current.id] != nil { + return .reply + } else { + return .none + } + + /* + if current.id == active.id { + return .main } if active.is_root_event() { if active.directly_references(current.id) { @@ -281,35 +290,31 @@ func determine_highlight(current: NostrEvent, active: NostrEvent) -> Highlight } return .none + */ } func calculated_collapsed_events(collapsed: Bool, active: NostrEvent, events: [NostrEvent]) -> [CollapsedEvent] { var count: Int = 0 + let reply_map = make_reply_map(active: active, events: events) + if !collapsed { return events.reduce(into: []) { acc, ev in - let highlight = determine_highlight(current: ev, active: active) + let highlight = determine_highlight(reply_map: reply_map, current: ev, active: active) return acc.append(.event(ev, highlight)) } } - let reply_map = make_reply_map(active: active, events: events) - let nevents = events.count var start: Int = 0 var i: Int = 0 return events.reduce(into: []) { (acc, ev) in - var highlight: Highlight = .none - if ev.id == active.id { - highlight = .main - } else if reply_map[ev.id] != nil { - highlight = .reply - } + let highlight = determine_highlight(reply_map: reply_map, current: ev, active: active) switch highlight { case .none: - if (i == 0) { + if i == 0 { start = 1 } count += 1