commit 695699aa103f793b6922933f3999d0ca182d805c
parent 0a4e75bfec7d557863f33bdccca76541b37fa646
Author: William Casarin <jb55@jb55.com>
Date: Thu, 30 Mar 2023 12:26:06 -0400
Fix broken npub searching
Diffstat:
1 file changed, 61 insertions(+), 54 deletions(-)
diff --git a/damus/Views/Search/SearchingEventView.swift b/damus/Views/Search/SearchingEventView.swift
@@ -46,6 +46,63 @@ struct SearchingEventView: View {
}
}
+ func handle_search(_ evid: String) {
+ self.search_state = .searching
+
+ switch search_type {
+ case .nip05:
+ if let pk = state.profiles.nip05_pubkey[evid] {
+ if state.profiles.lookup(id: pk) != nil {
+ self.search_state = .found_profile(pk)
+ }
+ } else {
+ Task.init {
+ guard let nip05 = NIP05.parse(evid) else {
+ self.search_state = .not_found
+ return
+ }
+ guard let nip05_resp = await fetch_nip05(nip05: nip05) else {
+ DispatchQueue.main.async {
+ self.search_state = .not_found
+ }
+ return
+ }
+
+ DispatchQueue.main.async {
+ guard let pk = nip05_resp.names[nip05.username] else {
+ self.search_state = .not_found
+ return
+ }
+
+ self.search_state = .found_profile(pk)
+ }
+ }
+ }
+
+ case .event:
+ if let ev = state.events.lookup(evid) {
+ self.search_state = .found(ev)
+ return
+ }
+ find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { ev in
+ if let ev {
+ self.search_state = .found(ev)
+ } else {
+ self.search_state = .not_found
+ }
+ }
+ case .profile:
+ find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { _ in
+ if state.profiles.lookup(id: evid) != nil {
+ self.search_state = .found_profile(evid)
+ return
+ } else {
+ self.search_state = .not_found
+ }
+ }
+ }
+ }
+
var body: some View {
Group {
switch search_state {
@@ -72,60 +129,10 @@ struct SearchingEventView: View {
}
}
.onChange(of: evid, debounceTime: 0.5) { evid in
- self.search_state = .searching
-
- switch search_type {
- case .nip05:
- if let pk = state.profiles.nip05_pubkey[evid] {
- if state.profiles.lookup(id: pk) != nil {
- self.search_state = .found_profile(pk)
- }
- } else {
- Task.init {
- guard let nip05 = NIP05.parse(evid) else {
- self.search_state = .not_found
- return
- }
- guard let nip05_resp = await fetch_nip05(nip05: nip05) else {
- DispatchQueue.main.async {
- self.search_state = .not_found
- }
- return
- }
-
- DispatchQueue.main.async {
- guard let pk = nip05_resp.names[nip05.username] else {
- self.search_state = .not_found
- return
- }
-
- self.search_state = .found_profile(pk)
- }
- }
- }
-
- case .event:
- if let ev = state.events.lookup(evid) {
- self.search_state = .found(ev)
- return
- }
- find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { ev in
- if let ev {
- self.search_state = .found(ev)
- } else {
- self.search_state = .not_found
- }
- }
- case .profile:
- find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { _ in
- if state.profiles.lookup(id: evid) != nil {
- self.search_state = .found_profile(evid)
- return
- } else {
- self.search_state = .not_found
- }
- }
- }
+ handle_search(evid)
+ }
+ .onAppear {
+ handle_search(evid)
}
}
}