diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift index 95e46fe5..160ce0fb 100644 --- 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 index 3cf50b4f..dc866d77 100644 --- 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))")