commit 0bac284eee592d1583b125b953c66fb6dcc19994
parent 07c95d1003ef4a9d0634f91c5b77d884006beb0c
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Wed, 11 Dec 2024 10:21:13 +0900
Fix issues with inputting a profile twice to the search bar
This fixes an issue where a user would have to input a profile npub
twice in order to get a result.
The fix is composed of the following constituents:
1. The removal of the dependency on NostrDB having profile information.
Previously the function relied on NostrDB having profile information
about a freshly downloaded profile, which it sometimes does not. The
function does not require the profile to be on NostrDB at the time
the profile is found on the relay.
2. The increase in allowed relay attempts to all relays. Previously it
would only look for about half of the relays, which could cause
certain events to not be found
3. The closing of relay subscription on EOSE. Previously, the
subscription would only be closed if an event was found, which could
lead to a "leak" of open subscriptions if an event is not found.
Closes: https://github.com/damus-io/damus/issues/2635
Changelog-Fixed: Fixed an issue where a profile would need to be input twice in the search to be found
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Diffstat:
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -931,7 +931,6 @@ enum FindEventType {
enum FoundEvent {
case profile(Pubkey)
- case invalid_profile(NostrEvent)
case event(NostrEvent)
}
@@ -988,10 +987,6 @@ func find_event_with_subid(state: DamusState, query query_: FindEvent, subid: St
switch query {
case .profile:
if ev.known_kind == .metadata {
- guard state.ndb.lookup_profile_key(ev.pubkey) != nil else {
- callback(.invalid_profile(ev))
- return
- }
callback(.profile(ev.pubkey))
}
case .event:
@@ -1000,17 +995,16 @@ func find_event_with_subid(state: DamusState, query query_: FindEvent, subid: St
case .eose:
if !has_event {
attempts += 1
- if attempts == state.pool.our_descriptors.count / 2 {
- callback(nil)
+ if attempts >= state.pool.our_descriptors.count {
+ callback(nil) // If we could not find any events in any of the relays we are connected to, send back nil
}
- state.pool.unsubscribe(sub_id: subid, to: [relay_id])
}
+ state.pool.unsubscribe(sub_id: subid, to: [relay_id]) // We are only finding an event once, so close subscription on eose
case .notice:
break
case .auth:
break
}
-
}
}