From 59898877236f6f5fd5911755319f0c18099b8876 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Fri, 4 Apr 2025 17:35:26 +0200 Subject: [PATCH] Add core delegate in contactsManager to get and remove friends from the list --- Linphone/Contacts/ContactsManager.swift | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Linphone/Contacts/ContactsManager.swift b/Linphone/Contacts/ContactsManager.swift index ec4b29692..7c27db878 100644 --- a/Linphone/Contacts/ContactsManager.swift +++ b/Linphone/Contacts/ContactsManager.swift @@ -28,6 +28,8 @@ import Combine final class ContactsManager: ObservableObject { + static let TAG = "[ContactsManager]" + static let shared = ContactsManager() private var coreContext = CoreContext.shared @@ -42,6 +44,7 @@ final class ContactsManager: ObservableObject { @Published var lastSearchSuggestions: [SearchResult] = [] @Published var avatarListModel: [ContactAvatarModel] = [] + private var coreDelegate: CoreDelegate? private var friendListDelegate: FriendListDelegate? private init() {} @@ -242,6 +245,8 @@ final class ContactsManager: ObservableObject { print("\(#function) - access denied") } } + + self.addCoreDelegate(core: core) } } @@ -453,6 +458,29 @@ final class ContactsManager: ObservableObject { completion(self.getFriendWithAddress(address: address)) } } + + func addCoreDelegate(core: Core) { + self.coreDelegate = CoreDelegateStub( + onFriendListCreated: { (_: Core, friendList: FriendList) in + Log.info("\(ContactsManager.TAG) Friend list \(friendList.displayName) created") + if self.friendListDelegate != nil { + friendList.addDelegate(delegate: self.friendListDelegate!) + } + }, onFriendListRemoved: { (_: Core, friendList: FriendList) in + Log.info("\(ContactsManager.TAG) Friend list \(friendList.displayName) removed") + if self.friendListDelegate != nil { + friendList.removeDelegate(delegate: self.friendListDelegate!) + } + }, onDefaultAccountChanged: { (_: Core, _: Account?) in + Log.info("\(ContactsManager.TAG) Default account changed, update all contacts' model showTrust value") + //updateContactsModelDependingOnDefaultAccountMode() + } + ) + + if self.coreDelegate != nil { + core.addDelegate(delegate: self.coreDelegate!) + } + } } struct PhoneNumber {