damus

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

commit e14cd99c85172be62660f38250506ac68020c03e
parent 0258ef792fad6948883e4f00783a8614ced813c4
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 21 Jan 2023 10:27:44 -0800

Add first_eref_mention helper to refactor embedded builder

Diffstat:
Mdamus/Nostr/NostrEvent.swift | 26++++++++++++++++++++++++++
Mdamus/Views/EventView.swift | 24++----------------------
2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -789,3 +789,29 @@ func inner_event_or_self(ev: NostrEvent) -> NostrEvent { return inner_ev } + + +func first_eref_mention(ev: NostrEvent, privkey: String?) -> Mention? { + let blocks = ev.blocks(privkey).filter { block in + guard case .mention(let mention) = block else { + return false + } + + guard case .event = mention.type else { + return false + } + + if mention.ref.key != "e" { + return false + } + + return true + } + + /// MARK: - Preview + if let firstBlock = blocks.first, case .mention(let mention) = firstBlock, mention.ref.key == "e" { + return mention + } + + return nil +} diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -245,30 +245,10 @@ struct EventView: View { .allowsHitTesting(!embedded) if !embedded { - let blocks = event.blocks(damus.keypair.privkey).filter { block in - guard case .mention(let mention) = block else { - return false - } - - guard case .event = mention.type else { - return false - } - - if mention.ref.key != "e" { - return false - } - - - return true - } - - /// MARK: - Preview - if let firstBlock = blocks.first, case .mention(let mention) = firstBlock, mention.ref.key == "e" { + if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) { BuilderEventView(damus: damus, event_id: mention.ref.id) } - } - - if !embedded { + if has_action_bar { if size == .selected { Text("\(format_date(event.created_at))")