From 26cbad1e46b93058bcd4732c2e6b1df9aa5b4026 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Fri, 6 Sep 2024 12:32:37 +0200 Subject: [PATCH] Rework logout : do not delete authinfo before the registration is in Cleared state --- Linphone/Core/CoreContext.swift | 17 ++++++++++++++++- Linphone/UI/Main/Fragments/HelpView.swift | 19 +++---------------- Linphone/UI/Main/Fragments/ToastView.swift | 9 ++++++++- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 9437069ef..3b9ca411b 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -201,6 +201,14 @@ final class CoreContext: ObservableObject { if self.mCore.consolidatedPresence != ConsolidatedPresence.Online { self.updatePresence(core: self.mCore, presence: ConsolidatedPresence.Online) } + } else if cbVal.state == .Cleared { + Log.info("[onAccountRegistrationStateChanged] Account \(cbVal.account.displayName()) registration was cleared. Looking for auth info") + if let authInfo = cbVal.account.findAuthInfo() { + Log.info("[onAccountRegistrationStateChanged] Found auth info for account, removing it") + cbVal.core.removeAuthInfo(info: authInfo) + } else { + Log.warn("[onAccountRegistrationStateChanged] Failed to find matching auth info for account") + } } else if cbVal.state != .Ok && cbVal.state != .Progress { // If registration failed, remove account from core self.monitor.pathUpdateHandler = { path in @@ -216,6 +224,7 @@ final class CoreContext: ObservableObject { } } } + TelecomManager.shared.onAccountRegistrationStateChanged(core: cbVal.core, account: cbVal.account, state: cbVal.state, message: cbVal.message) DispatchQueue.main.async { @@ -224,10 +233,16 @@ final class CoreContext: ObservableObject { self.loggedIn = true } else if cbVal.state == .Progress || cbVal.state == .Refreshing { self.loggingInProgress = true + } else if cbVal.state == .Cleared { + self.loggingInProgress = false + self.loggedIn = false + self.hasDefaultAccount = false + ToastViewModel.shared.toastMessage = "Success_account_logged_out" + ToastViewModel.shared.displayToast = true } else { self.loggingInProgress = false self.loggedIn = false - ToastViewModel.shared.toastMessage = "Registration failed" + ToastViewModel.shared.toastMessage = "Registration_failed" ToastViewModel.shared.displayToast = true } } diff --git a/Linphone/UI/Main/Fragments/HelpView.swift b/Linphone/UI/Main/Fragments/HelpView.swift index af227f297..17cf680bf 100644 --- a/Linphone/UI/Main/Fragments/HelpView.swift +++ b/Linphone/UI/Main/Fragments/HelpView.swift @@ -40,22 +40,9 @@ class HelpView { // TODO (basic debug moved here until halp view is implemented) static func logout() { CoreContext.shared.doOnCoreQueue { core in - if core.defaultAccount != nil { - let authInfo = core.defaultAccount!.findAuthInfo() - if authInfo != nil { - Log.info("$TAG Found auth info for account, removing it") - core.removeAuthInfo(info: authInfo!) - } else { - Log.warn("$TAG Failed to find matching auth info for account") - } - - core.removeAccount(account: core.defaultAccount!) - Log.info("$TAG Account has been removed") - - DispatchQueue.main.async { - CoreContext.shared.hasDefaultAccount = false - CoreContext.shared.loggedIn = false - } + if let account = core.defaultAccount { + Log.info("Account \(account.displayName()) has been removed") + core.removeAccount(account: account) // UI update and auth info removal moved into onRegistrationChanged core callback, in CoreContext } } } diff --git a/Linphone/UI/Main/Fragments/ToastView.swift b/Linphone/UI/Main/Fragments/ToastView.swift index b696d2228..7ef3d9d63 100644 --- a/Linphone/UI/Main/Fragments/ToastView.swift +++ b/Linphone/UI/Main/Fragments/ToastView.swift @@ -122,13 +122,20 @@ struct ToastView: View { .default_text_style(styleSize: 15) .padding(8) - case "Registration failed": + case "Registration_failed": Text("The user name or password is incorrects") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) + case "Success_account_logged_out": + Text("Account successfully logged out") + .multilineTextAlignment(.center) + .foregroundStyle(Color.greenSuccess500) + .default_text_style(styleSize: 15) + .padding(8) + case "Success_toast_call_transfer_successful": Text("Call has been successfully transferred") .multilineTextAlignment(.center)