commit eb41846bb91960234606add39cf60e95ddd5e3d3
parent f7946b1a7ce8c73ef9f75c6802d9809399f300ea
Author: Charlie Fish <contact@charlie.fish>
Date: Sun, 7 Jan 2024 13:16:09 -0700
search: prioritize friends when autocompleting
Lightning-Address: fishcharlie@strike.me
Closes: https://github.com/damus-io/damus/issues/1620
Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Changelog-Changed: Prioritize friends when autocompleting
Diffstat:
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift
@@ -1,5 +1,5 @@
//
-// UserAutocompletion.swift
+// UserSearch.swift
// damus
//
// Created by William Casarin on 2023-01-28.
@@ -18,7 +18,17 @@ struct UserSearch: View {
var users: [Pubkey] {
let txn = NdbTxn(ndb: damus_state.ndb)
- return search_profiles(profiles: damus_state.profiles, search: search, txn: txn)
+ 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 before `b`
+ return true
+ } else {
+ return false
+ }
+ }
}
func on_user_tapped(pk: Pubkey) {
diff --git a/damus/Views/Profile/ProfileName.swift b/damus/Views/Profile/ProfileName.swift
@@ -10,6 +10,13 @@ import SwiftUI
enum FriendType {
case friend
case fof
+
+ var priority: Int {
+ switch self {
+ case .friend: return 2
+ case .fof: return 1
+ }
+ }
}
func get_friend_type(contacts: Contacts, pubkey: Pubkey) -> FriendType? {