diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index e39c5db94..3fba105a3 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -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 { diff --git a/Linphone/Utils/MagicSearchSingleton.swift b/Linphone/Utils/MagicSearchSingleton.swift index d74e7035f..4f2d3c429 100644 --- a/Linphone/Utils/MagicSearchSingleton.swift +++ b/Linphone/Utils/MagicSearchSingleton.swift @@ -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],