From 035149bd47074869e75edd5636fbf286f16c6b72 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 11 Dec 2023 17:00:01 +0100 Subject: [PATCH] Fix callbacks --- Linphone/Core/CoreContext.swift | 15 ++++++ Linphone/Localizable.xcstrings | 6 +++ .../Contacts/Model/ContactAvatarModel.swift | 19 ++++++++ Linphone/UI/Main/Fragments/SideMenu.swift | 33 ------------- .../ViewModel/HistoryListViewModel.swift | 46 +++++-------------- 5 files changed, 52 insertions(+), 67 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index f2592ae60..10e723c1e 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -20,6 +20,7 @@ // swiftlint:disable large_tuple import linphonesw import Combine +import UniformTypeIdentifiers final class CoreContext: ObservableObject { @@ -156,6 +157,20 @@ final class CoreContext: ObservableObject { TelecomManager.shared.onCallStateChanged(core: cbVal.core, call: cbVal.call, state: cbVal.state, message: cbVal.message) } + self.mCore.publisher?.onLogCollectionUploadStateChanged?.postOnMainQueue { (cbValue: (_: Core, _: Core.LogCollectionUploadState, info: String)) in + print("publisherpublisher onLogCollectionUploadStateChanged") + + if cbValue.info.starts(with: "https") { + UIPasteboard.general.setValue( + cbValue.info, + forPasteboardType: UTType.plainText.identifier + ) + + ToastViewModel.shared.toastMessage = "Success_copied_into_clipboard" + ToastViewModel.shared.displayToast.toggle() + } + } + self.mIteratePublisher = Timer.publish(every: 0.02, on: .main, in: .common) .autoconnect() .receive(on: coreQueue) diff --git a/Linphone/Localizable.xcstrings b/Linphone/Localizable.xcstrings index 569f38f71..b3982d479 100644 --- a/Linphone/Localizable.xcstrings +++ b/Linphone/Localizable.xcstrings @@ -217,6 +217,9 @@ }, "Contacts" : { + }, + "Content" : { + }, "Continue" : { @@ -486,6 +489,9 @@ }, "This contact will be deleted definitively." : { + }, + "Title" : { + }, "TLS" : { diff --git a/Linphone/UI/Main/Contacts/Model/ContactAvatarModel.swift b/Linphone/UI/Main/Contacts/Model/ContactAvatarModel.swift index 777b12e8f..3c6bc2d26 100644 --- a/Linphone/UI/Main/Contacts/Model/ContactAvatarModel.swift +++ b/Linphone/UI/Main/Contacts/Model/ContactAvatarModel.swift @@ -64,6 +64,24 @@ class ContactAvatarModel: ObservableObject { } func addDelegate() { + + /* + self.friend?.publisher?.onPresenceReceived?.postOnMainQueue { (cbValue: (Friend)) in + print("publisherpublisher onLogCollectionUploadStateChanged \(cbValue.address?.asStringUriOnly())") + + self.presenceStatus = cbValue.consolidatedPresence + if cbValue.consolidatedPresence == .Online || cbValue.consolidatedPresence == .Busy { + if cbValue.consolidatedPresence == .Online || cbValue.presenceModel!.latestActivityTimestamp != -1 { + self.lastPresenceInfo = cbValue.consolidatedPresence == .Online ? "Online" : self.getCallTime(startDate: cbValue.presenceModel!.latestActivityTimestamp) + } else { + self.lastPresenceInfo = "Away" + } + } else { + self.lastPresenceInfo = "" + } + } + */ + let newFriendDelegate = FriendDelegateStub( onPresenceReceived: { (linphoneFriend: Friend) -> Void in DispatchQueue.main.sync { @@ -80,6 +98,7 @@ class ContactAvatarModel: ObservableObject { } } ) + friendDelegate = newFriendDelegate if friendDelegate != nil { diff --git a/Linphone/UI/Main/Fragments/SideMenu.swift b/Linphone/UI/Main/Fragments/SideMenu.swift index 60f3c9606..3c65be7d5 100644 --- a/Linphone/UI/Main/Fragments/SideMenu.swift +++ b/Linphone/UI/Main/Fragments/SideMenu.swift @@ -25,8 +25,6 @@ struct SideMenu: View { @ObservedObject private var coreContext = CoreContext.shared - @State private var coreDelegate: CoreDelegate? - let width: CGFloat let isOpen: Bool let menuClose: () -> Void @@ -75,37 +73,6 @@ struct SideMenu: View { func sendLogs() { coreContext.doOnCoreQueue { core in core.uploadLogCollection() - - let newCoreDelegate = CoreDelegateStub( - onLogCollectionUploadStateChanged: { core, logCollectionUploadState, logString in - - if logString.starts(with: "https") { - UIPasteboard.general.setValue( - logString, - forPasteboardType: UTType.plainText.identifier - ) - - removeAllDelegate() - - ToastViewModel.shared.toastMessage = "Success_copied_into_clipboard" - ToastViewModel.shared.displayToast.toggle() - } - } - ) - - coreDelegate = newCoreDelegate - if coreDelegate != nil { - core.addDelegate(delegate: coreDelegate!) - } - } - } - - func removeAllDelegate() { - coreContext.doOnCoreQueue { core in - if coreDelegate != nil { - core.removeDelegate(delegate: coreDelegate!) - coreDelegate = nil - } } } } diff --git a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift index a16ea380e..974710f9a 100644 --- a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift +++ b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift @@ -26,12 +26,9 @@ class HistoryListViewModel: ObservableObject { @Published var callLogs: [CallLog] = [] var callLogsTmp: [CallLog] = [] - @Published private var coreDelegate: CoreDelegate? - var callLogsAddressToDelete = "" init() { - removeAllDelegate() computeCallLogsList() } @@ -49,29 +46,20 @@ class HistoryListViewModel: ObservableObject { self.callLogsTmp.append(log) } } - /* - DispatchQueue.main.async { - self.coreDelegate = CoreDelegateStub( - onCallLogUpdated: { (_: Core, _: CallLog) -> Void in - DispatchQueue.main.sync { - let account = core.defaultAccount - let logs = account != nil ? account!.callLogs : core.callLogs - - self.callLogs.removeAll() - self.callLogsTmp.removeAll() - - logs.forEach { log in - self.callLogs.append(log) - self.callLogsTmp.append(log) - } - } - } - ) - if self.coreDelegate != nil { - core.addDelegate(delegate: self.coreDelegate!) + + core.publisher?.onCallLogUpdated?.postOnMainQueue { (_: (_: Core, _: CallLog)) in + print("publisherpublisher onCallLogUpdated") + let account = core.defaultAccount + let logs = account != nil ? account!.callLogs : core.callLogs + + self.callLogs.removeAll() + self.callLogsTmp.removeAll() + + logs.forEach { log in + self.callLogs.append(log) + self.callLogsTmp.append(log) } } - */ } } @@ -210,14 +198,4 @@ class HistoryListViewModel: ObservableObject { let indexTmp = self.callLogsTmp.firstIndex(where: {$0.callId == callLog.callId}) self.callLogsTmp.remove(at: indexTmp!) } - - func removeAllDelegate() { - coreContext.doOnCoreQueue { core in - if self.coreDelegate != nil { - core.removeDelegate(delegate: self.coreDelegate!) - self.coreDelegate = nil - } - } - } - }