damus

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

commit f78eeb1f22a14d818fe0d9291c4f55813c882d1c
parent a007e18add771e149c29266cd858d61e5b247a27
Author: Bryan Montz <bryanmontz@me.com>
Date:   Fri,  5 May 2023 21:57:47 -0500

Fix npub search fails on the first try

Co-authored-by: William Casarin <jb55@jb55.com>
Changelog-Fixed: Fix npub search fails on the first try
Closes: #1044
Closes: #1100

Diffstat:
Mdamus/ContentView.swift | 10+++++++++-
Mdamus/Models/HomeModel.swift | 4+++-
Mdamus/Views/Search/SearchingEventView.swift | 3+--
3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -751,8 +751,16 @@ func find_event(state: DamusState, evid: String, search_type: SearchType, find_f break case .event(_, let ev): has_event = true - callback(ev) + state.pool.unsubscribe(sub_id: subid) + + if search_type == .profile && ev.known_kind == .metadata { + process_metadata_event(events: state.events, our_pubkey: state.pubkey, profiles: state.profiles, ev: ev) { + callback(ev) + } + } else { + callback(ev) + } case .eose: if !has_event { attempts += 1 diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -761,10 +761,11 @@ func guard_valid_event(events: EventCache, ev: NostrEvent, callback: @escaping ( } } -func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Profiles, ev: NostrEvent) { +func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Profiles, ev: NostrEvent, completion: (() -> Void)? = nil) { guard_valid_event(events: events, ev: ev) { DispatchQueue.global(qos: .background).async { guard let profile: Profile = decode_data(Data(ev.content.utf8)) else { + completion?() return } @@ -772,6 +773,7 @@ func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Pr DispatchQueue.main.async { process_metadata_profile(our_pubkey: our_pubkey, profiles: profiles, profile: profile, ev: ev) + completion?() } } } diff --git a/damus/Views/Search/SearchingEventView.swift b/damus/Views/Search/SearchingEventView.swift @@ -92,10 +92,9 @@ struct SearchingEventView: View { } } case .profile: - find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { _ in + find_event(state: state, evid: evid, search_type: search_type, find_from: nil) { ev in if state.profiles.lookup(id: evid) != nil { self.search_state = .found_profile(evid) - return } else { self.search_state = .not_found }