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
This commit is contained in:
committed by
William Casarin
parent
a007e18add
commit
f78eeb1f22
@@ -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
|
||||
|
||||
@@ -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?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user