damus

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

commit a4a046560582ac9500e8109f205373f7494cdf78
parent 3056ab9bfb8e601900598927ef0b7870d2e19ade
Author: kernelkind <kernelkind@gmail.com>
Date:   Thu, 18 Jan 2024 14:59:29 -0500

nip19: add naddr link support

Add functionality for when user taps on naddr link they get redirected
to the proper note.

Closes: https://github.com/damus-io/damus/issues/1806

Changelog-Added: Add naddr link support
Lightning-url: LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G
Signed-off-by: kernelkind <kernelkind@gmail.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/ContentView.swift | 33++++++++++++++++++++++++++++++++-
Mdamus/Nostr/NostrLink.swift | 2+-
2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -941,6 +941,34 @@ func find_event_with_subid(state: DamusState, query query_: FindEvent, subid: St } } +func naddrLookup(damus_state: DamusState, naddr: NAddr, callback: @escaping (NostrEvent?) -> ()) { + var nostrKinds: [NostrKind]? = NostrKind(rawValue: naddr.kind).map { [$0] } + + let filter = NostrFilter(kinds: nostrKinds, authors: [naddr.author]) + + let subid = UUID().description + + damus_state.pool.subscribe_to(sub_id: subid, filters: [filter], to: nil) { relay_id, res in + guard case .nostr_event(let ev) = res else { + damus_state.pool.unsubscribe(sub_id: subid, to: [relay_id]) + return + } + + if case .event(_, let ev) = ev { + for tag in ev.tags { + if(tag.count >= 2 && tag[0].string() == "d"){ + if (tag[1].string() == naddr.identifier){ + damus_state.pool.unsubscribe(sub_id: subid, to: [relay_id]) + callback(ev) + return + } + } + } + } + damus_state.pool.unsubscribe(sub_id: subid, to: [relay_id]) + } +} + func timeline_name(_ timeline: Timeline?) -> String { guard let timeline else { return "" @@ -1093,7 +1121,10 @@ func on_open_url(state: DamusState, url: URL, result: @escaping (OpenResult?) -> // doesn't really make sense here break case .naddr(let naddr): - break // TODO: fix + naddrLookup(damus_state: state, naddr: naddr) { res in + guard let res = res else { return } + result(.event(res)) + } } case .filter(let filt): result(.filter(filt)) diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift @@ -79,7 +79,7 @@ func decode_nostr_bech32_uri(_ s: String) -> NostrLink? { case .nscript(let data): return .script(data) case .naddr(let naddr): - return .none // TODO: FIX + return .ref(.naddr(naddr)) case .nevent(let nevent): return .ref(.event(nevent.noteid)) case .nprofile(let nprofile):