From 2f95e7b4d3116f6d86577440b81cdf5927b3dcc3 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Fri, 7 Mar 2025 17:24:58 +0100 Subject: [PATCH] Add searchForContactsWithoutCoreThread function --- Linphone/Contacts/ContactsManager.swift | 2 +- Linphone/Utils/MagicSearchSingleton.swift | 30 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Linphone/Contacts/ContactsManager.swift b/Linphone/Contacts/ContactsManager.swift index 3f8a039b5..ec4b29692 100644 --- a/Linphone/Contacts/ContactsManager.swift +++ b/Linphone/Contacts/ContactsManager.swift @@ -88,7 +88,7 @@ final class ContactsManager: ObservableObject { } } - MagicSearchSingleton.shared.searchForContacts(sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) + MagicSearchSingleton.shared.searchForContactsWithoutCoreThread(sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) let store = CNContactStore() store.requestAccess(for: .contacts) { (granted, error) in diff --git a/Linphone/Utils/MagicSearchSingleton.swift b/Linphone/Utils/MagicSearchSingleton.swift index c3d217578..f1d3b25e0 100644 --- a/Linphone/Utils/MagicSearchSingleton.swift +++ b/Linphone/Utils/MagicSearchSingleton.swift @@ -107,8 +107,8 @@ final class MagicSearchSingleton: ObservableObject { } } - func searchForContacts(sourceFlags: Int) { - coreContext.doOnCoreQueue { _ in + func searchForContactsWithoutCoreThread(sourceFlags: Int) { + if self.magicSearch != nil { var needResetCache = false if let oldFilter = self.previousFilter { @@ -118,7 +118,6 @@ final class MagicSearchSingleton: ObservableObject { } self.previousFilter = self.currentFilter - if needResetCache { self.magicSearch.resetSearchCache() } @@ -131,6 +130,31 @@ final class MagicSearchSingleton: ObservableObject { } } + func searchForContacts(sourceFlags: Int) { + if self.magicSearch != nil { + coreContext.doOnCoreQueue { _ in + var needResetCache = false + + if let oldFilter = self.previousFilter { + if oldFilter.count > self.currentFilter.count || oldFilter != self.currentFilter { + needResetCache = true + } + } + self.previousFilter = self.currentFilter + + if needResetCache { + self.magicSearch.resetSearchCache() + } + + self.magicSearch.getContactsListAsync( + filter: self.currentFilter, + domain: self.allContact ? "" : self.domainDefaultAccount, + sourceFlags: sourceFlags, + aggregation: MagicSearch.Aggregation.Friend) + } + } + } + func searchForSuggestions() { coreContext.doOnCoreQueue { _ in var needResetCache = false