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
|
break
|
||||||
case .event(_, let ev):
|
case .event(_, let ev):
|
||||||
has_event = true
|
has_event = true
|
||||||
callback(ev)
|
|
||||||
state.pool.unsubscribe(sub_id: subid)
|
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:
|
case .eose:
|
||||||
if !has_event {
|
if !has_event {
|
||||||
attempts += 1
|
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) {
|
guard_valid_event(events: events, ev: ev) {
|
||||||
DispatchQueue.global(qos: .background).async {
|
DispatchQueue.global(qos: .background).async {
|
||||||
guard let profile: Profile = decode_data(Data(ev.content.utf8)) else {
|
guard let profile: Profile = decode_data(Data(ev.content.utf8)) else {
|
||||||
|
completion?()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,6 +773,7 @@ func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Pr
|
|||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
process_metadata_profile(our_pubkey: our_pubkey, profiles: profiles, profile: profile, ev: ev)
|
process_metadata_profile(our_pubkey: our_pubkey, profiles: profiles, profile: profile, ev: ev)
|
||||||
|
completion?()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,9 @@ struct SearchingEventView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .profile:
|
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 {
|
if state.profiles.lookup(id: evid) != nil {
|
||||||
self.search_state = .found_profile(evid)
|
self.search_state = .found_profile(evid)
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
self.search_state = .not_found
|
self.search_state = .not_found
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user