diff --git a/src/libclient/accountmodel.cpp b/src/libclient/accountmodel.cpp index 1dd57e88ccb98e4bc82bc6e5ca09adb213bebfa5..3bf692718292a053181ed79565a80f650e8acc22 100644 --- a/src/libclient/accountmodel.cpp +++ b/src/libclient/accountmodel.cpp @@ -290,26 +290,28 @@ AccountModel::getAccountConfig(const QString& accountId) const } void -AccountModel::setAlias(const QString& accountId, const QString& alias) +AccountModel::setAlias(const QString& accountId, const QString& alias, bool save) { auto& accountInfo = pimpl_->getAccountInfo(accountId); if (accountInfo.profileInfo.alias == alias) return; accountInfo.profileInfo.alias = alias; - authority::storage::createOrUpdateProfile(accountInfo.id, accountInfo.profileInfo); + if (save) + authority::storage::createOrUpdateProfile(accountInfo.id, accountInfo.profileInfo); + Q_EMIT profileUpdated(accountId); } void -AccountModel::setAvatar(const QString& accountId, const QString& avatar) +AccountModel::setAvatar(const QString& accountId, const QString& avatar, bool save) { auto& accountInfo = pimpl_->getAccountInfo(accountId); if (accountInfo.profileInfo.avatar == avatar) return; accountInfo.profileInfo.avatar = avatar; - authority::storage::createOrUpdateProfile(accountInfo.id, accountInfo.profileInfo); - + if (save) + authority::storage::createOrUpdateProfile(accountInfo.id, accountInfo.profileInfo); Q_EMIT profileUpdated(accountId); } diff --git a/src/libclient/api/accountmodel.h b/src/libclient/api/accountmodel.h index 07a7f4c4e36ba4dd6084c80a1ec8e1ca66d8df38..62f4c5453dd3ce00a71fdad6cba48f0b52a5bf2c 100644 --- a/src/libclient/api/accountmodel.h +++ b/src/libclient/api/accountmodel.h @@ -140,14 +140,14 @@ public: * @param avatar * @throws out_of_range exception if account is not found */ - void setAvatar(const QString& accountId, const QString& avatar); + void setAvatar(const QString& accountId, const QString& avatar, bool save = true); /** * Change the alias of an account * @param accountId * @param alias * @throws out_of_range exception if account is not found */ - void setAlias(const QString& accountId, const QString& alias); + void setAlias(const QString& accountId, const QString& alias, bool save = true); /** * Try to register a name * @param accountId diff --git a/src/libclient/contactmodel.cpp b/src/libclient/contactmodel.cpp index b1eaf237d799835c408a8f833b2ddd4dbf3ff4ae..b43c407b2cfa5d8046ed5186fa66c81f804f7ab0 100644 --- a/src/libclient/contactmodel.cpp +++ b/src/libclient/contactmodel.cpp @@ -1211,16 +1211,15 @@ ContactModelPimpl::slotProfileReceived(const QString& accountId, profileInfo.alias = e.split(":")[1]; if (peer == linked.owner.profileInfo.uri) { - if (!profileInfo.avatar.isEmpty()) { - auto dest = storage::getPath() + accountId + "/profile.vcf"; - QFile oldvCard(dest); - if (oldvCard.exists()) - oldvCard.remove(); - vCardFile.rename(dest); - linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias); - linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar); - Q_EMIT linked.profileUpdated(peer); - } + auto avatarChanged = profileInfo.avatar != linked.owner.profileInfo.avatar; + auto aliasChanged = profileInfo.alias != linked.owner.profileInfo.alias; + if (profileInfo.avatar.isEmpty()) + return; // In this case, probably a new device without avatar. + // Only save the new profile once + if (aliasChanged) + linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias, !avatarChanged); + if (avatarChanged) + linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar, true); return; } vCardFile.remove();