nip19: add search functionality for naddr, nprofile & nevent
The user is able to search for naddr, nprofile & nevent bech32 entities. Additionally, these entities and others are able to have prefixes such as damus:nostr: and damus.io links. Closes: https://github.com/damus-io/damus/issues/1841 Closes: https://github.com/damus-io/damus/issues/1650 Changelog-Added: Add ability to search for naddr, nprofiles, nevents 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>
This commit is contained in:
committed by
William Casarin
parent
a4a0465605
commit
0650a62791
@@ -18,6 +18,7 @@ enum SearchType: Equatable {
|
||||
case event(NoteId)
|
||||
case profile(Pubkey)
|
||||
case nip05(String)
|
||||
case naddr(NAddr)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@@ -35,6 +36,8 @@ struct SearchingEventView: View {
|
||||
return "Profile"
|
||||
case .event:
|
||||
return "Note"
|
||||
case .naddr:
|
||||
return "Naddr"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +92,14 @@ struct SearchingEventView: View {
|
||||
}
|
||||
self.search_state = .found_profile(pubkey)
|
||||
}
|
||||
case .naddr(let naddr):
|
||||
naddrLookup(damus_state: state, naddr: naddr) { res in
|
||||
guard let res = res else {
|
||||
self.search_state = .not_found
|
||||
return
|
||||
}
|
||||
self.search_state = .found(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ enum Search: Identifiable {
|
||||
case nip05(String)
|
||||
case hex(Data)
|
||||
case multi(MultiSearch)
|
||||
case nevent(NEvent)
|
||||
case naddr(NAddr)
|
||||
case nprofile(NProfile)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
@@ -30,6 +33,9 @@ enum Search: Identifiable {
|
||||
case .nip05: return "nip05"
|
||||
case .hex: return "hex"
|
||||
case .multi: return "multi"
|
||||
case .nevent: return "nevent"
|
||||
case .naddr: return "naddr"
|
||||
case .nprofile: return "nprofile"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,27 +68,25 @@ struct InnerSearchResults: View {
|
||||
switch search {
|
||||
case .profiles(let results):
|
||||
ProfilesSearch(results)
|
||||
|
||||
case .hashtag(let ht):
|
||||
HashtagSearch(ht)
|
||||
|
||||
case .nip05(let addr):
|
||||
SearchingEventView(state: damus_state, search_type: .nip05(addr))
|
||||
|
||||
case .profile(let pubkey):
|
||||
SearchingEventView(state: damus_state, search_type: .profile(pubkey))
|
||||
|
||||
case .hex(let h):
|
||||
|
||||
VStack(spacing: 10) {
|
||||
SearchingEventView(state: damus_state, search_type: .event(NoteId(h)))
|
||||
|
||||
SearchingEventView(state: damus_state, search_type: .profile(Pubkey(h)))
|
||||
}
|
||||
|
||||
}
|
||||
case .note(let nid):
|
||||
SearchingEventView(state: damus_state, search_type: .event(nid))
|
||||
|
||||
case .nevent(let nevent):
|
||||
SearchingEventView(state: damus_state, search_type: .event(nevent.noteid))
|
||||
case .nprofile(let nprofile):
|
||||
SearchingEventView(state: damus_state, search_type: .profile(nprofile.author))
|
||||
case .naddr(let naddr):
|
||||
SearchingEventView(state: damus_state, search_type: .naddr(naddr))
|
||||
case .multi(let multi):
|
||||
VStack {
|
||||
HashtagSearch(multi.hashtag)
|
||||
@@ -142,21 +146,35 @@ func search_for_string<Y>(profiles: Profiles, search new: String, txn: NdbTxn<Y>
|
||||
return .hashtag(make_hashtagable(new))
|
||||
}
|
||||
|
||||
if let new = hex_decode_id(new) {
|
||||
let searchQuery = remove_nostr_uri_prefix(new)
|
||||
|
||||
if let new = hex_decode_id(searchQuery) {
|
||||
return .hex(new)
|
||||
}
|
||||
|
||||
if new.starts(with: "npub") {
|
||||
if let decoded = bech32_pubkey_decode(new) {
|
||||
if searchQuery.starts(with: "npub") {
|
||||
if let decoded = bech32_pubkey_decode(searchQuery) {
|
||||
return .profile(decoded)
|
||||
}
|
||||
}
|
||||
|
||||
if new.starts(with: "note"), let decoded = try? bech32_decode(new) {
|
||||
if searchQuery.starts(with: "note"), let decoded = try? bech32_decode(searchQuery) {
|
||||
return .note(NoteId(decoded.data))
|
||||
}
|
||||
|
||||
let multisearch = MultiSearch(hashtag: make_hashtagable(new), profiles: search_profiles(profiles: profiles, search: new, txn: txn))
|
||||
if searchQuery.starts(with: "nevent"), case let .nevent(nevent) = Bech32Object.parse(searchQuery) {
|
||||
return .nevent(nevent)
|
||||
}
|
||||
|
||||
if searchQuery.starts(with: "nprofile"), case let .nprofile(nprofile) = Bech32Object.parse(searchQuery) {
|
||||
return .nprofile(nprofile)
|
||||
}
|
||||
|
||||
if searchQuery.starts(with: "naddr"), case let .naddr(naddr) = Bech32Object.parse(searchQuery) {
|
||||
return .naddr(naddr)
|
||||
}
|
||||
|
||||
let multisearch = MultiSearch(hashtag: make_hashtagable(searchQuery), profiles: search_profiles(profiles: profiles, search: new, txn: txn))
|
||||
return .multi(multisearch)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user