From 3056ab9bfb8e601900598927ef0b7870d2e19ade Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 18 Jan 2024 14:59:28 -0500 Subject: [PATCH] nip19: add EventLoaderView for nevent mentions Allow nevent mentions to be loaded in the MentionView since they are just a note with extra metadata. Lightning-url: LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G Signed-off-by: kernelkind Reviewed-by: William Casarin Signed-off-by: William Casarin --- damus/Nostr/NostrEvent.swift | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift index 98697ce1..1af77394 100644 --- a/damus/Nostr/NostrEvent.swift +++ b/damus/Nostr/NostrEvent.swift @@ -739,22 +739,30 @@ func validate_event(ev: NostrEvent) -> ValidationResult { func first_eref_mention(ev: NostrEvent, keypair: Keypair) -> Mention? { let blocks = ev.blocks(keypair).blocks.filter { block in - guard case .mention(let mention) = block, - case .note = mention.ref else { + guard case .mention(let mention) = block else { + return false + } + + switch mention.ref { + case .note, .nevent: + return true + default: return false } - - return true } /// MARK: - Preview if let firstBlock = blocks.first, - case .mention(let mention) = firstBlock, - case .note(let note_id) = mention.ref - { - return .note(note_id) + case .mention(let mention) = firstBlock { + switch mention.ref { + case .note(let note_id): + return .note(note_id) + case .nevent(let nevent): + return .note(nevent.noteid) + default: + return nil + } } - return nil }