From d2ddf011447508cfb6a56c6541b1a46ba29ad516 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Mon, 3 Feb 2025 12:13:42 +0100 Subject: [PATCH] Fix removing account --- Linphone/model/account/AccountManager.cpp | 10 +------ Linphone/model/account/AccountModel.cpp | 32 +++++++++++++++++------ Linphone/model/account/AccountModel.hpp | 3 ++- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Linphone/model/account/AccountManager.cpp b/Linphone/model/account/AccountManager.cpp index 1e29b138b..ed3365334 100644 --- a/Linphone/model/account/AccountManager.cpp +++ b/Linphone/model/account/AccountManager.cpp @@ -129,15 +129,7 @@ bool AccountManager::login(QString username, if (mAccountModel && account == mAccountModel->getAccount()) { if (state == linphone::RegistrationState::Failed) { connect( - mAccountModel.get(), &AccountModel::removedFromCore, this, - [this]() { - auto authInfo = mAccountModel->getMonitor()->findAuthInfo(); - if (authInfo) { - qDebug() << log().arg("Removing auth info after failing to connect on login"); - CoreModel::getInstance()->getCore()->removeAuthInfo(authInfo); - } - mAccountModel = nullptr; - }, + mAccountModel.get(), &AccountModel::removed, this, [this]() { mAccountModel = nullptr; }, Qt::SingleShotConnection); mAccountModel->removeAccount(); } else if (state == linphone::RegistrationState::Ok) { diff --git a/Linphone/model/account/AccountModel.cpp b/Linphone/model/account/AccountModel.cpp index 3321257ad..309ce0987 100644 --- a/Linphone/model/account/AccountModel.cpp +++ b/Linphone/model/account/AccountModel.cpp @@ -48,7 +48,18 @@ AccountModel::AccountModel(const std::shared_ptr &account, QO }); connect(CoreModel::getInstance().get(), &CoreModel::accountRemoved, this, [this](const std::shared_ptr &core, const std::shared_ptr &account) { - if (account == mMonitor) emit removedFromCore(); + if (account == mMonitor) { + if (mToRemove && account->getState() == linphone::RegistrationState::None) { + lInfo() << log().arg("Disabled account removed"); + auto authInfo = mMonitor->findAuthInfo(); + if (authInfo) { + lInfo() << log().arg("Removing authinfo for disabled account"); + CoreModel::getInstance()->getCore()->removeAuthInfo(authInfo); + } + removeUserData(mMonitor); + emit removed(); + } + } }); } @@ -59,10 +70,13 @@ AccountModel::~AccountModel() { void AccountModel::onRegistrationStateChanged(const std::shared_ptr &account, linphone::RegistrationState state, const std::string &message) { - if (state == linphone::RegistrationState::Cleared) { - qDebug() << log().arg("Account removed"); + // Cleared and None are the last state on processes after being change. Check for accountRemoved for account that + // was not registered. + if (mToRemove && (state == linphone::RegistrationState::Cleared || state == linphone::RegistrationState::None)) { + lInfo() << log().arg("Account removed on state [%1]").arg((int)state); auto authInfo = mMonitor->findAuthInfo(); if (authInfo) { + lInfo() << log().arg("Removing authinfo"); CoreModel::getInstance()->getCore()->removeAuthInfo(authInfo); } removeUserData(mMonitor); @@ -122,11 +136,13 @@ void AccountModel::setDefault() { void AccountModel::removeAccount() { auto core = CoreModel::getInstance()->getCore(); auto params = mMonitor ? mMonitor->getParams() : nullptr; - qDebug() << log() - .arg("Removing account [%1]") - .arg(params && params->getIdentityAddress() - ? Utils::coreStringToAppString(params->getIdentityAddress()->asString()) - : "Null"); + lInfo() << log() + .arg("Removing account [%1]") + .arg(params && params->getIdentityAddress() + ? Utils::coreStringToAppString(params->getIdentityAddress()->asString()) + : "Null"); + mToRemove = true; + if (mMonitor) core->removeAccount(mMonitor); } std::shared_ptr AccountModel::getAccount() const { diff --git a/Linphone/model/account/AccountModel.hpp b/Linphone/model/account/AccountModel.hpp index 10315206e..50a739fcc 100644 --- a/Linphone/model/account/AccountModel.hpp +++ b/Linphone/model/account/AccountModel.hpp @@ -109,7 +109,6 @@ signals: void audioVideoConferenceFactoryAddressChanged(QString value); void limeServerUrlChanged(QString value); void removed(); - void removedFromCore(); void voicemailCountChanged(int count); void showMwiChanged(bool show); void voicemailAddressChanged(QString value); @@ -128,6 +127,8 @@ private: static std::shared_ptr getUserData(const std::shared_ptr &account); static void removeUserData(const std::shared_ptr &account); + bool mToRemove = false; + DECLARE_ABSTRACT_OBJECT };