Skip to content
Snippets Groups Projects
Commit a01b5780 authored by Léopold Chappuis's avatar Léopold Chappuis Committed by Léopold Chappuis
Browse files

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
parent 04fca1fc
Branches
Tags
No related merge requests found
daemon @ 9c3465ba
Subproject commit 57e91daefea5c3d8e3604c3cc2b6c1d2adbed0d5
Subproject commit 9c3465ba7c2dfe7d5c061bf4a4adab2ffdb2f5c1
......@@ -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);
});
}
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment