Closed tyiu closed 2 weeks ago
Before | After |
---|---|
On Thu, May 02, 2024 at 06:09:55PM -0400, Terry Yiu wrote:
Closes: https://github.com/damus-io/damus/pull/2199
LGTM!
Reviewed-by: William Casarin @.***>
Cc'ing Daniel: can you apply this?
Thanks!
damus/Views/Posting/UserSearch.swift | 12 +----------- damus/Views/SearchResultsView.swift | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift index c4136e35d..3957d166c 100644 --- a/damus/Views/Posting/UserSearch.swift +++ b/damus/Views/Posting/UserSearch.swift @@ -18,17 +18,7 @@ struct UserSearch: View {
var users: [Pubkey] { guard let txn = NdbTxn(ndb: damus_state.ndb) else { return [] }
- return search_profiles(profiles: damus_state.profiles, search: search, txn: txn).sorted { a, b in
- let aFriendTypePriority = get_friend_type(contacts: damus_state.contacts, pubkey: a)?.priority ?? 0
- let bFriendTypePriority = get_friend_type(contacts: damus_state.contacts, pubkey: b)?.priority ?? 0
- if aFriendTypePriority > bFriendTypePriority {
- //
a
should be sorted beforeb
- return true
- } else {
- return false
- }
- }
return search_profiles(profiles: damus_state.profiles, contacts: damus_state.contacts, search: search, txn: txn) }
func on_user_tapped(pk: Pubkey) { diff --git a/damus/Views/SearchResultsView.swift b/damus/Views/SearchResultsView.swift index 469a185f5..4af89f566 100644 --- a/damus/Views/SearchResultsView.swift +++ b/damus/Views/SearchResultsView.swift @@ -113,11 +113,11 @@ struct SearchResultsView: View { .frame(maxHeight: .infinity) .onAppear { guard let txn = NdbTxn.init(ndb: damus_state.ndb) else { return }
- self.result = search_for_string(profiles: damus_state.profiles, search: search, txn: txn)
- self.result = search_for_string(profiles: damus_state.profiles, contacts: damus_state.contacts, search: search, txn: txn) } .onChange(of: search) { new in guard let txn = NdbTxn.init(ndb: damus_state.ndb) else { return }
- self.result = search_for_string(profiles: damus_state.profiles, search: search, txn: txn)
- self.result = search_for_string(profiles: damus_state.profiles, contacts: damus_state.contacts, search: search, txn: txn) } } } @@ -131,7 +131,7 @@ struct SearchResultsView_Previews: PreviewProvider { */
-func search_for_string
(profiles: Profiles, search new: String, txn: NdbTxn ) -> Search? { +func search_for_string (profiles: Profiles, contacts: Contacts, search new: String, txn: NdbTxn ) -> Search? { guard new.count != 0 else { return nil } @@ -174,7 +174,7 @@ func search_for_string (profiles: Profiles, search new: String, txn: NdbTxn return .naddr(naddr) }
- let multisearch = MultiSearch(hashtag: make_hashtagable(searchQuery), profiles: search_profiles(profiles: profiles, search: new, txn: txn))
- let multisearch = MultiSearch(hashtag: make_hashtagable(searchQuery), profiles: search_profiles(profiles: profiles, contacts: contacts, search: new, txn: txn)) return .multi(multisearch) }
@@ -191,7 +191,7 @@ func makehashtagable( str: String) -> String { return String(new.filter{$0 != " "}) }
-func search_profiles
(profiles: Profiles, search: String, txn: NdbTxn ) -> [Pubkey] { +func search_profiles (profiles: Profiles, contacts: Contacts, search: String, txn: NdbTxn ) -> [Pubkey] { // Search by hex pubkey. if let pubkey = hex_decode_pubkey(search), profiles.lookup_key_by_pubkey(pubkey) != nil @@ -208,8 +208,16 @@ func search_profiles (profiles: Profiles, search: String, txn: NdbTxn ) -> [ return [pk] }
let new = search.lowercased()
return profiles.search(search, limit: 10, txn: txn).sorted { a, b in
let aFriendTypePriority = get_friend_type(contacts: contacts, pubkey: a)?.priority ?? 0
let bFriendTypePriority = get_friend_type(contacts: contacts, pubkey: b)?.priority ?? 0
return profiles.search(search, limit: 10, txn: txn)
if aFriendTypePriority > bFriendTypePriority {
//
a
should be sorted beforeb
return true
} else {
return false
}
} }