From 7712952afe08bc72a40c95ea83b2f4645915dd18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 20 Jul 2018 13:05:14 -0400
Subject: [PATCH] newaccountmodel: wait for accountDetailsChanged before
 settings credentials and fix realm

Change-Id: I84a5a65451816f6f87c5a91851f42cfb5cac4920
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
---
 src/newaccountmodel.cpp | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp
index 47110bbe..ceefcd25 100644
--- a/src/newaccountmodel.cpp
+++ b/src/newaccountmodel.cpp
@@ -184,17 +184,6 @@ NewAccountModel::setAccountConfig(const std::string& accountId,
         details[ConfProperties::USERNAME] = toQString(confProperties.username);
     }
     configurationManager.setAccountDetails(QString::fromStdString(accountId), details);
-
-    // Refresh credentials for SIP accounts
-    if (accountInfo.profileInfo.type == profile::Type::SIP) {
-        MapStringString credentials;
-        credentials[ConfProperties::USERNAME] = toQString(confProperties.username);
-        credentials[ConfProperties::PASSWORD] = toQString(confProperties.password);
-        credentials[ConfProperties::REALM] = QString("*");
-        QVector<MapStringString> credentialsVec;
-        credentialsVec.append(credentials);
-        ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec);
-    }
 }
 
 account::ConfProperties_t
@@ -363,6 +352,20 @@ NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, co
     }
 
     accountInfo->second.fromDetails(convertMap(details));
+
+    // Refresh credentials for SIP accounts
+    if (accountInfo->second.profileInfo.type == profile::Type::SIP) {
+        auto& confProperties = accountInfo->second.confProperties;
+        MapStringString credentials;
+        using namespace DRing::Account;
+        credentials[ConfProperties::USERNAME] = toQString(confProperties.username);
+        credentials[ConfProperties::PASSWORD] = toQString(confProperties.password);
+        credentials[ConfProperties::REALM] = confProperties.realm.empty()? QString("*") : toQString(confProperties.realm);
+        QVector<MapStringString> credentialsVec;
+        credentialsVec.append(credentials);
+        ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec);
+    }
+
     emit linked.accountStatusChanged(accountId);
 }
 
-- 
GitLab