Rework logout : do not delete authinfo before the registration is in Cleared state

This commit is contained in:
QuentinArguillere 2024-09-06 12:32:37 +02:00
parent cec5d99915
commit 26cbad1e46
3 changed files with 27 additions and 18 deletions

View file

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

View file

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

View file

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