Fix being call after removing the account: do not remove auth info before the account has been correctly removed (unREGISTER sent)

This commit is contained in:
Julien Wadel 2025-01-30 16:08:46 +01:00
parent 3e57429534
commit d74ccc32bd
2 changed files with 22 additions and 12 deletions

View file

@ -128,10 +128,14 @@ bool AccountManager::login(QString username,
const std::string &message) { const std::string &message) {
if (mAccountModel && account == mAccountModel->getAccount()) { if (mAccountModel && account == mAccountModel->getAccount()) {
if (state == linphone::RegistrationState::Failed) { if (state == linphone::RegistrationState::Failed) {
core->removeAuthInfo(authInfo); connect(
core->removeAccount(account); mAccountModel.get(), &AccountModel::removed, this,
emit mAccountModel->removeListener(); [this]() {
mAccountModel = nullptr; emit mAccountModel->removeListener();
mAccountModel = nullptr;
},
Qt::SingleShotConnection);
mAccountModel->removeAccount();
} else if (state == linphone::RegistrationState::Ok) { } else if (state == linphone::RegistrationState::Ok) {
core->setDefaultAccount(account); core->setDefaultAccount(account);
emit mAccountModel->removeListener(); emit mAccountModel->removeListener();

View file

@ -55,6 +55,15 @@ AccountModel::~AccountModel() {
void AccountModel::onRegistrationStateChanged(const std::shared_ptr<linphone::Account> &account, void AccountModel::onRegistrationStateChanged(const std::shared_ptr<linphone::Account> &account,
linphone::RegistrationState state, linphone::RegistrationState state,
const std::string &message) { 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); emit registrationStateChanged(account, state, message);
} }
@ -92,7 +101,7 @@ void AccountModel::setPictureUri(QString uri) {
// Hack because Account doesn't provide callbacks on updated data // Hack because Account doesn't provide callbacks on updated data
// emit pictureUriChanged(uri); // emit pictureUriChanged(uri);
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
emit CoreModel::getInstance() -> defaultAccountChanged(core, core->getDefaultAccount()); emit CoreModel::getInstance()->defaultAccountChanged(core, core->getDefaultAccount());
} }
void AccountModel::onDefaultAccountChanged() { void AccountModel::onDefaultAccountChanged() {
@ -108,13 +117,10 @@ void AccountModel::setDefault() {
void AccountModel::removeAccount() { void AccountModel::removeAccount() {
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
auto authInfo = mMonitor->findAuthInfo(); qDebug() << log()
if (authInfo) { .arg("Removing account [%1]")
core->removeAuthInfo(authInfo); .arg(mMonitor ? Utils::coreStringToAppString(mMonitor->getContactAddress()->asString()) : "Null");
}
core->removeAccount(mMonitor); core->removeAccount(mMonitor);
removeUserData(mMonitor);
emit removed();
} }
std::shared_ptr<linphone::Account> AccountModel::getAccount() const { std::shared_ptr<linphone::Account> AccountModel::getAccount() const {
@ -150,7 +156,7 @@ void AccountModel::setDisplayName(QString displayName) {
// Hack because Account doesn't provide callbacks on updated data // Hack because Account doesn't provide callbacks on updated data
// emit displayNameChanged(displayName); // emit displayNameChanged(displayName);
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
emit CoreModel::getInstance() -> defaultAccountChanged(core, core->getDefaultAccount()); emit CoreModel::getInstance()->defaultAccountChanged(core, core->getDefaultAccount());
} }
void AccountModel::setDialPlan(int index) { void AccountModel::setDialPlan(int index) {