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
This commit is contained in:
committed by
William Casarin
parent
f7946b1a7c
commit
eb41846bb9
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// UserAutocompletion.swift
|
// UserSearch.swift
|
||||||
// damus
|
// damus
|
||||||
//
|
//
|
||||||
// Created by William Casarin on 2023-01-28.
|
// Created by William Casarin on 2023-01-28.
|
||||||
@@ -18,7 +18,17 @@ struct UserSearch: View {
|
|||||||
|
|
||||||
var users: [Pubkey] {
|
var users: [Pubkey] {
|
||||||
let txn = NdbTxn(ndb: damus_state.ndb)
|
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) {
|
func on_user_tapped(pk: Pubkey) {
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ import SwiftUI
|
|||||||
enum FriendType {
|
enum FriendType {
|
||||||
case friend
|
case friend
|
||||||
case fof
|
case fof
|
||||||
|
|
||||||
|
var priority: Int {
|
||||||
|
switch self {
|
||||||
|
case .friend: return 2
|
||||||
|
case .fof: return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_friend_type(contacts: Contacts, pubkey: Pubkey) -> FriendType? {
|
func get_friend_type(contacts: Contacts, pubkey: Pubkey) -> FriendType? {
|
||||||
|
|||||||
Reference in New Issue
Block a user