Store magicSearch.allContacts to display the entire contact list when the app starts

This commit is contained in:
Benoit Martins 2025-10-30 15:04:19 +01:00
parent bb4134ede0
commit 8c9784a21d
2 changed files with 18 additions and 2 deletions

View file

@ -522,7 +522,7 @@ struct ContentView: View {
Button {
sharedMainViewModel.displayedFriend = nil
isMenuOpen = false
magicSearch.allContact = true
magicSearch.changeAllContact(allContactBool: true)
magicSearch.searchForContacts()
} label: {
HStack {
@ -540,7 +540,7 @@ struct ContentView: View {
Button {
sharedMainViewModel.displayedFriend = nil
isMenuOpen = false
magicSearch.allContact = false
magicSearch.changeAllContact(allContactBool: false)
magicSearch.searchForContacts()
} label: {
HStack {

View file

@ -37,6 +37,8 @@ final class MagicSearchSingleton: ObservableObject {
private var limitSearchToLinphoneAccounts = true
@Published var allContact = false
let allContactKey = "all_contact"
private var domainDefaultAccount = ""
var searchDelegate: MagicSearchDelegate?
@ -52,6 +54,13 @@ final class MagicSearchSingleton: ObservableObject {
}
private init() {
let preferences = UserDefaults.standard
if preferences.object(forKey: allContactKey) == nil {
preferences.set(allContact, forKey: allContactKey)
} else {
allContact = preferences.bool(forKey: allContactKey)
}
coreContext.doOnCoreQueue { core in
self.domainDefaultAccount = core.defaultAccount?.params?.domain ?? ""
@ -148,6 +157,13 @@ final class MagicSearchSingleton: ObservableObject {
magicSearch.addDelegate(delegate: self.searchDelegate!)
}
}
func changeAllContact(allContactBool: Bool) {
let preferences = UserDefaults.standard
allContact = allContactBool
preferences.set(allContact, forKey: allContactKey)
}
func updateContacts(
sortedLastSearch: [SearchResult],