diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 9f8e1d5bf..b6699bb8c 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -123,6 +123,9 @@ final class CoreContext: ObservableObject { if cbVal.state == .Ok { self.loggingInProgress = false self.loggedIn = true + if self.mCore.consolidatedPresence != ConsolidatedPresence.Online { + self.onForeground() + } } else if cbVal.state == .Progress { self.loggingInProgress = true } else { @@ -154,6 +157,30 @@ final class CoreContext: ObservableObject { } } + + func onForeground() { + coreQueue.async { + // We can't rely on defaultAccount?.params?.isPublishEnabled + // as it will be modified by the SDK when changing the presence status + if self.mCore.config!.getBool(section: "app", key: "publish_presence", defaultValue: true) { + NSLog("App is in foreground, PUBLISHING presence as Online") + self.mCore.consolidatedPresence = ConsolidatedPresence.Online + } + } + } + + func onBackground() { + coreQueue.async { + // We can't rely on defaultAccount?.params?.isPublishEnabled + // as it will be modified by the SDK when changing the presence status + if self.mCore.config!.getBool(section: "app", key: "publish_presence", defaultValue: true) { + NSLog("App is in background, un-PUBLISHING presence info") + // We don't use ConsolidatedPresence.Busy but Offline to do an unsubscribe, + // Flexisip will handle the Busy status depending on other devices + self.mCore.consolidatedPresence = ConsolidatedPresence.Offline + } + } + } } // swiftlint:enable large_tuple diff --git a/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift b/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift index abb0fda21..2e5f702f1 100644 --- a/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift +++ b/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift @@ -504,7 +504,6 @@ struct EditContactFragment: View { let result = ContactsManager.shared.lastSearch.firstIndex(where: { $0.friend!.name == newContact.firstName + " " + newContact.lastName }) - print("getFriendIndexWithFriendgetFriendIndexWithFriend \(newContact.firstName) \(newContact.lastName) \(result)") contactViewModel.indexDisplayedFriend = result } } diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 186b5fd3f..9096f3117 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -625,11 +625,13 @@ struct ContentView: View { } .onChange(of: scenePhase) { newPhase in if newPhase == .active { + coreContext.onForeground() contactsManager.fetchContacts() print("Active") } else if newPhase == .inactive { print("Inactive") } else if newPhase == .background { + coreContext.onBackground() print("Background") } }