diff --git a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml index d5e99a09c3f26e2f0b5ec3db9ceee7b0b8beb4f0..ce48ee83a8073f92a7d908188af0394bb72a9e73 100644 --- a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml +++ b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml @@ -579,6 +579,11 @@ <arg type="s" name="accountId" direction="in"/> <arg type="s" name="displayName" direction="in"/> <arg type="s" name="avatar" direction="in"/> + <arg type="s" name="fileType" direction="in"> + <tp:docstring> + The file type of the avatar, for now JPEG or PNG + </tp:docstring> + </arg> <arg type="i" name="flag" direction="in"/> <tp:docstring> Update the profile of the account and send it to peers. diff --git a/bin/dbus/dbusconfigurationmanager.hpp b/bin/dbus/dbusconfigurationmanager.hpp index b5d267a678bfb0582b9ce4d55a076785f2e5bf35..b418c7b9a7d5a7dbcca44f85a9fe55145d499f0c 100644 --- a/bin/dbus/dbusconfigurationmanager.hpp +++ b/bin/dbus/dbusconfigurationmanager.hpp @@ -217,9 +217,9 @@ public: } void - updateProfile(const std::string& accountID,const std::string& displayName, const std::string& avatar, const int32_t& flag) + updateProfile(const std::string& accountID,const std::string& displayName, const std::string& avatar, const std::string& fileType, const int32_t& flag) { - libjami::updateProfile(accountID, displayName, avatar, flag); + libjami::updateProfile(accountID, displayName, avatar, fileType, flag); } auto diff --git a/bin/jni/configurationmanager.i b/bin/jni/configurationmanager.i index af6e2a87a87e1eb6d1273a0c626b6334b9a05628..2fca6883aa9bc9476d520c3ce729ff544c7b500b 100644 --- a/bin/jni/configurationmanager.i +++ b/bin/jni/configurationmanager.i @@ -90,7 +90,7 @@ std::vector<std::map<std::string, std::string>> getConnectionList(const std::str std::vector<std::map<std::string, std::string>> getChannelList(const std::string& accountId, const std::string& connectionId); std::string addAccount(const std::map<std::string, std::string>& details); void removeAccount(const std::string& accountId); -void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag); +void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar,const std::string& fileType, int32_t flag); std::vector<std::string> getAccountList(); void sendRegister(const std::string& accountId, bool enable); void registerAllAccounts(void); diff --git a/bin/nodejs/configurationmanager.i b/bin/nodejs/configurationmanager.i index 8cc261ee5c91b74d1b82e64c977a0c1ee9b2564b..1b09d14eaf28c5b1abf1ed682469d5f643952f0b 100644 --- a/bin/nodejs/configurationmanager.i +++ b/bin/nodejs/configurationmanager.i @@ -86,7 +86,7 @@ std::vector<std::map<std::string, std::string>> getConnectionList(const std::str std::vector<std::map<std::string, std::string>> getChannelList(const std::string& accountId, const std::string& connectionId); std::string addAccount(const std::map<std::string, std::string>& details); void removeAccount(const std::string& accountId); -void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag); +void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar,const std::string& fileType, int32_t flag); std::vector<std::string> getAccountList(); void sendRegister(const std::string& accountId, bool enable); void registerAllAccounts(void); diff --git a/src/account.h b/src/account.h index c38ab4fa4befcf4a1d7127645d8463dc7c141d93..1d6fccae3b4dccecce0970a0de501ad99c37338c 100644 --- a/src/account.h +++ b/src/account.h @@ -210,7 +210,7 @@ public: virtual std::map<std::string, std::string> getNearbyPeers() const { return {}; } - virtual void updateProfile(const std::string& /*displayName*/, const std::string& /*avatar*/, int32_t /*flag*/) = 0; + virtual void updateProfile(const std::string& /*displayName*/, const std::string& /*avatar*/, const std::string& /*fileType*/, int32_t /*flag*/) = 0; std::map<std::string, std::string> getProfileVcard() const; diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index e46ca3db1884833102f9f38dc190f4f1af71ef78..a48a689f55cc7dcb3e1799de56149ba9a524af69 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -294,10 +294,10 @@ getNearbyPeers(const std::string& accountId) } void -updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag) +updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, const std::string& fileType, int32_t flag) { if (const auto acc = jami::Manager::instance().getAccount(accountId)){ - acc->updateProfile(displayName, avatar, flag); + acc->updateProfile(displayName, avatar, fileType, flag); } } diff --git a/src/jami/configurationmanager_interface.h b/src/jami/configurationmanager_interface.h index 31a08cff61e582de5cb737d9e7d443b1d4373436..239f1e5f2aa84364530f370bf59e8042fd3e535b 100644 --- a/src/jami/configurationmanager_interface.h +++ b/src/jami/configurationmanager_interface.h @@ -104,7 +104,7 @@ LIBJAMI_PUBLIC bool cancelMessage(const std::string& accountId, uint64_t message LIBJAMI_PUBLIC std::vector<Message> getLastMessages(const std::string& accountId, const uint64_t& base_timestamp); LIBJAMI_PUBLIC std::map<std::string, std::string> getNearbyPeers(const std::string& accountId); -LIBJAMI_PUBLIC void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag); +LIBJAMI_PUBLIC void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar,const std::string& fileType, int32_t flag); LIBJAMI_PUBLIC int getMessageStatus(uint64_t id); LIBJAMI_PUBLIC int getMessageStatus(const std::string& accountId, uint64_t id); LIBJAMI_PUBLIC void setIsComposing(const std::string& accountId, diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 64be3b823c3103ffd346c8718614fc998cabe7ae..32e06a0a0952eb6f72f3b2f104969ec64e23ab2b 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -3411,8 +3411,11 @@ JamiAccount::sendProfileToPeers() void JamiAccount::updateProfile(const std::string& displayName, const std::string& avatar, + const std::string& fileType, int32_t flag) { + // if the fileType is empty then only the display name will be upated + const auto& accountUri = accountManager_->getInfo()->accountId; const auto& path = profilePath(); const auto& profiles = idPath_ / "profiles"; @@ -3437,24 +3440,25 @@ JamiAccount::updateProfile(const std::string& displayName, editConfig([&](JamiAccountConfig& config) { config.displayName = displayName; }); emitSignal<libjami::ConfigurationSignal::AccountDetailsChanged>(getAccountID(), getAccountDetails()); - if (flag == 0) { - vCard::utils::removeByKey(profile, "PHOTO"); - const auto& avatarPath = std::filesystem::path(avatar); - if (std::filesystem::exists(avatarPath)) { - try { - const auto& base64 = jami::base64::encode(fileutils::loadFile(avatarPath)); - profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = base64; - } catch (const std::exception& e) { - JAMI_ERROR("Failed to load avatar: {}", e.what()); + + if (!fileType.empty()) { + const std::string& key = "PHOTO;ENCODING=BASE64;TYPE=" + fileType; + if (flag == 0) { + vCard::utils::removeByKey(profile, "PHOTO"); + const auto& avatarPath = std::filesystem::path(avatar); + if (std::filesystem::exists(avatarPath)) { + try { + const auto& base64 = jami::base64::encode(fileutils::loadFile(avatarPath)); + profile[key] = base64; + } catch (const std::exception& e) { + JAMI_ERROR("Failed to load avatar: {}", e.what()); + } } + } else if (flag == 1) { + vCard::utils::removeByKey(profile, "PHOTO"); + profile[key] = avatar; } - } else if (flag == 1) { - vCard::utils::removeByKey(profile, "PHOTO"); - profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = avatar; } - - // nothing happens to the profile photo if the avatarPath is invalid - // and not empty. So far it seems to be the best default behavior. try { std::filesystem::path tmpPath = vCardPath.string() + ".tmp"; std::ofstream file(tmpPath); diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index d23221611cc713e34f0769a5dd19ee783937a992..a9e6e6a2697b3a333ea15a6367ef407676ccef43 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -426,7 +426,7 @@ public: * @param avatar Current or new avatar * @param flag 0 for path to avatar, 1 for base64 avatar */ - void updateProfile(const std::string& displayName, const std::string& avatar, int32_t flag) override; + void updateProfile(const std::string& displayName, const std::string& avatar, const std::string& fileType, int32_t flag) override; #ifdef LIBJAMI_TESTABLE dhtnet::ConnectionManager& connectionManager() { return *connectionManager_; } diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index 735138bc59d99f2c567257df9889382306d7a48d..8b543c109d4dbbc290b9fdb5a3bca28cf7855e01 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -148,6 +148,7 @@ SIPAccount::~SIPAccount() noexcept void SIPAccount::updateProfile(const std::string& displayName, const std::string& avatar, + const std::string& fileType, int32_t flag) { auto vCardPath = idPath_ / "profile.vcf"; @@ -158,21 +159,24 @@ SIPAccount::updateProfile(const std::string& displayName, } profile["FN"] = displayName; - if (flag == 0) { - vCard::utils::removeByKey(profile, "PHOTO"); - const auto& avatarPath = std::filesystem::path(avatar); - if (std::filesystem::exists(avatarPath)) { - try { - profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = base64::encode(fileutils::loadFile(avatarPath)); - } catch (const std::exception& e) { - JAMI_ERROR("Failed to load avatar: {}", e.what()); - } - } else if (avatarPath.empty()) { + if (!fileType.empty()) { + const std::string& key = "PHOTO;ENCODING=BASE64;TYPE=" + fileType; + if (flag == 0) { vCard::utils::removeByKey(profile, "PHOTO"); - profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = ""; + const auto& avatarPath = std::filesystem::path(avatar); + if (std::filesystem::exists(avatarPath)) { + try { + profile[key] = base64::encode(fileutils::loadFile(avatarPath)); + } catch (const std::exception& e) { + JAMI_ERROR("Failed to load avatar: {}", e.what()); + } + } else if (avatarPath.empty()) { + vCard::utils::removeByKey(profile, "PHOTO"); + profile[key] = ""; + } + } else if (flag == 1) { + profile[key] = avatar; } - } else if (flag == 1) { - profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = avatar; } // nothing happens to the profile photo if the avatarPath is invalid diff --git a/src/sip/sipaccount.h b/src/sip/sipaccount.h index ff7927be0e818eba69819905ee05de84fef6fd1e..bdf7ea4f1c1e3bb5b8c7ef65764bf84b693013ba 100644 --- a/src/sip/sipaccount.h +++ b/src/sip/sipaccount.h @@ -130,7 +130,7 @@ public: /** * updates SIP account profile */ - void updateProfile(const std::string& displayName, const std::string& avatar, int32_t flag) override; + void updateProfile(const std::string& displayName, const std::string& avatar, const std::string& fileType, int32_t flag) override; /** * Initialize the SIP voip link with the account parameters and send registration