Add searchForContactsWithoutCoreThread function

This commit is contained in:
Benoit Martins 2025-03-07 17:24:58 +01:00
parent 273c77edbe
commit 2f95e7b4d3
2 changed files with 28 additions and 4 deletions

View file

@ -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

View file

@ -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