From a01b57809950a4f0b5f87d191a19818a5644b54e Mon Sep 17 00:00:00 2001 From: Leopold Chappuis <leopold.chappuis@savoirfairelinux.com> Date: Wed, 13 Nov 2024 09:45:41 -0500 Subject: [PATCH] update-profile: moved to new API for setting Avatar This change only impacts avatar updates; moving to the new API for updating the displayName is still pending and may require additional work. Specifically, we need to provide the current profile picture path to prevent its removal during the update process. Change-Id: Idbc1592eda2b533b633cc366c72224f5e1bdce98 --- daemon | 2 +- src/app/accountadapter.cpp | 11 +++----- src/libclient/accountmodel.cpp | 13 +++++++--- src/libclient/api/accountmodel.h | 2 +- .../qtwrapper/configurationmanager_wrap.h | 25 +++++++++++++++++-- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/daemon b/daemon index 57e91daef..9c3465ba7 160000 --- a/daemon +++ b/daemon @@ -1 +1 @@ -Subproject commit 57e91daefea5c3d8e3604c3cc2b6c1d2adbed0d5 +Subproject commit 9c3465ba7c2dfe7d5c061bf4a4adab2ffdb2f5c1 diff --git a/src/app/accountadapter.cpp b/src/app/accountadapter.cpp index 95d7d730f..3f687dfe7 100644 --- a/src/app/accountadapter.cpp +++ b/src/app/accountadapter.cpp @@ -114,7 +114,7 @@ AccountAdapter::createJamiAccount(const QVariantMap& settings) &lrcInstance_->accountModel(), &lrc::api::AccountModel::accountAdded, [this, registeredName, settings](const QString& accountId) { - lrcInstance_->accountModel().setAvatar(accountId, settings["avatar"].toString()); + lrcInstance_->accountModel().setAvatar(accountId, settings["avatar"].toString(), true,1); Utils::oneShotConnect(&lrcInstance_->accountModel(), &lrc::api::AccountModel::accountDetailsChanged, [this](const QString& accountId) { @@ -303,13 +303,8 @@ AccountAdapter::setCurrentAccountAvatarFile(const QString& source) return; } - QByteArray ba; - QBuffer bu(&ba); - bu.open(QIODevice::WriteOnly); - image.save(&bu, "PNG"); - auto str = QString::fromLocal8Bit(ba.toBase64()); auto accountId = lrcInstance_->get_currentAccountId(); - lrcInstance_->accountModel().setAvatar(accountId, str); + lrcInstance_->accountModel().setAvatar(accountId, source); }); } @@ -318,7 +313,7 @@ AccountAdapter::setCurrentAccountAvatarBase64(const QString& data) { auto futureResult = QtConcurrent::run([this, data]() { auto accountId = lrcInstance_->get_currentAccountId(); - lrcInstance_->accountModel().setAvatar(accountId, data); + lrcInstance_->accountModel().setAvatar(accountId, data, true, 1); }); } diff --git a/src/libclient/accountmodel.cpp b/src/libclient/accountmodel.cpp index 07af96f4c..3483f67f2 100644 --- a/src/libclient/accountmodel.cpp +++ b/src/libclient/accountmodel.cpp @@ -284,20 +284,25 @@ AccountModel::setAlias(const QString& accountId, const QString& alias, bool save accountInfo.profileInfo.alias = alias; if (save) - storage::vcard::setProfile(accountInfo.id, accountInfo.profileInfo); + ConfigurationManager::instance().updateProfile(accountId, + alias, + "", + 5);// flag out of range to avoid updating avatar Q_EMIT profileUpdated(accountId); } void -AccountModel::setAvatar(const QString& accountId, const QString& avatar, bool save) +AccountModel::setAvatar(const QString& accountId, const QString& avatar, bool save, int flag) { auto& accountInfo = pimpl_->getAccountInfo(accountId); if (accountInfo.profileInfo.avatar == avatar) return; accountInfo.profileInfo.avatar = avatar; - if (save) - storage::vcard::setProfile(accountInfo.id, accountInfo.profileInfo); + ConfigurationManager::instance().updateProfile(accountId, + accountInfo.profileInfo.alias, + avatar, + flag); Q_EMIT profileUpdated(accountId); } diff --git a/src/libclient/api/accountmodel.h b/src/libclient/api/accountmodel.h index ba58eddf2..e68b0cf8b 100644 --- a/src/libclient/api/accountmodel.h +++ b/src/libclient/api/accountmodel.h @@ -144,7 +144,7 @@ public: * @param avatar * @throws out_of_range exception if account is not found */ - void setAvatar(const QString& accountId, const QString& avatar, bool save = true); + void setAvatar(const QString& accountId, const QString& avatar, bool save = true, int flag =0); /** * Change the alias of an account * @param accountId diff --git a/src/libclient/qtwrapper/configurationmanager_wrap.h b/src/libclient/qtwrapper/configurationmanager_wrap.h index 8692f0e39..157e05af6 100644 --- a/src/libclient/qtwrapper/configurationmanager_wrap.h +++ b/src/libclient/qtwrapper/configurationmanager_wrap.h @@ -469,7 +469,10 @@ public Q_SLOTS: // METHODS address.toStdString()); } - bool registerName(const QString& accountId, const QString& name, const QString& scheme, const QString& password) + bool registerName(const QString& accountId, + const QString& name, + const QString& scheme, + const QString& password) { return libjami::registerName(accountId.toStdString(), name.toStdString(), @@ -483,6 +486,21 @@ public Q_SLOTS: // METHODS return temp; } + void updateProfile(const QString& accountId, + const QString& displayName, + const QString& avatarPath, + int flag) + { + // file type is set to PNG by default + // it can be changed to JPEG to optimize compression + libjami::updateProfile(accountId.toStdString(), + displayName.toStdString(), + avatarPath.toStdString(), + "PNG", + flag + ); + } + QStringList getAccountList() { return convertStringList(libjami::getAccountList()); @@ -835,7 +853,10 @@ public Q_SLOTS: // METHODS libjami::removeContact(accountId.toStdString(), uri.toStdString(), ban); } - void revokeDevice(const QString& accountId, const QString& deviceId, const QString& scheme, const QString& password) + void revokeDevice(const QString& accountId, + const QString& deviceId, + const QString& scheme, + const QString& password) { libjami::revokeDevice(accountId.toStdString(), deviceId.toStdString(), -- GitLab