diff --git a/Linphone/model/account/AccountManager.cpp b/Linphone/model/account/AccountManager.cpp index 3895f6c79..6db687f59 100644 --- a/Linphone/model/account/AccountManager.cpp +++ b/Linphone/model/account/AccountManager.cpp @@ -128,10 +128,14 @@ bool AccountManager::login(QString username, const std::string &message) { if (mAccountModel && account == mAccountModel->getAccount()) { if (state == linphone::RegistrationState::Failed) { - core->removeAuthInfo(authInfo); - core->removeAccount(account); - emit mAccountModel->removeListener(); - mAccountModel = nullptr; + connect( + mAccountModel.get(), &AccountModel::removed, this, + [this]() { + emit mAccountModel->removeListener(); + mAccountModel = nullptr; + }, + Qt::SingleShotConnection); + mAccountModel->removeAccount(); } else if (state == linphone::RegistrationState::Ok) { core->setDefaultAccount(account); emit mAccountModel->removeListener(); diff --git a/Linphone/model/account/AccountModel.cpp b/Linphone/model/account/AccountModel.cpp index 4eaae99b0..fe952adf6 100644 --- a/Linphone/model/account/AccountModel.cpp +++ b/Linphone/model/account/AccountModel.cpp @@ -55,6 +55,15 @@ 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"); + auto authInfo = mMonitor->findAuthInfo(); + if (authInfo) { + CoreModel::getInstance()->getCore()->removeAuthInfo(authInfo); + } + removeUserData(mMonitor); + emit removed(); + } emit registrationStateChanged(account, state, message); } @@ -92,7 +101,7 @@ void AccountModel::setPictureUri(QString uri) { // Hack because Account doesn't provide callbacks on updated data // emit pictureUriChanged(uri); auto core = CoreModel::getInstance()->getCore(); - emit CoreModel::getInstance() -> defaultAccountChanged(core, core->getDefaultAccount()); + emit CoreModel::getInstance()->defaultAccountChanged(core, core->getDefaultAccount()); } void AccountModel::onDefaultAccountChanged() { @@ -108,13 +117,10 @@ void AccountModel::setDefault() { void AccountModel::removeAccount() { auto core = CoreModel::getInstance()->getCore(); - auto authInfo = mMonitor->findAuthInfo(); - if (authInfo) { - core->removeAuthInfo(authInfo); - } + qDebug() << log() + .arg("Removing account [%1]") + .arg(mMonitor ? Utils::coreStringToAppString(mMonitor->getContactAddress()->asString()) : "Null"); core->removeAccount(mMonitor); - removeUserData(mMonitor); - emit removed(); } std::shared_ptr AccountModel::getAccount() const { @@ -150,7 +156,7 @@ void AccountModel::setDisplayName(QString displayName) { // Hack because Account doesn't provide callbacks on updated data // emit displayNameChanged(displayName); auto core = CoreModel::getInstance()->getCore(); - emit CoreModel::getInstance() -> defaultAccountChanged(core, core->getDefaultAccount()); + emit CoreModel::getInstance()->defaultAccountChanged(core, core->getDefaultAccount()); } void AccountModel::setDialPlan(int index) {