Add first_eref_mention helper to refactor embedded builder
This commit is contained in:
@@ -789,3 +789,29 @@ func inner_event_or_self(ev: NostrEvent) -> NostrEvent {
|
|||||||
|
|
||||||
return inner_ev
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -245,30 +245,10 @@ struct EventView: View {
|
|||||||
.allowsHitTesting(!embedded)
|
.allowsHitTesting(!embedded)
|
||||||
|
|
||||||
if !embedded {
|
if !embedded {
|
||||||
let blocks = event.blocks(damus.keypair.privkey).filter { block in
|
if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) {
|
||||||
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" {
|
|
||||||
BuilderEventView(damus: damus, event_id: mention.ref.id)
|
BuilderEventView(damus: damus, event_id: mention.ref.id)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !embedded {
|
|
||||||
if has_action_bar {
|
if has_action_bar {
|
||||||
if size == .selected {
|
if size == .selected {
|
||||||
Text("\(format_date(event.created_at))")
|
Text("\(format_date(event.created_at))")
|
||||||
|
|||||||
Reference in New Issue
Block a user