From a1bba4d761de6f3588f82c90f4dad8ec6da0bf49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Wed, 20 Nov 2024 11:38:41 -0500
Subject: [PATCH] updateProfile: use int32 for flag

Change-Id: Ia844cbac3ffb529d5ee55c0c589c94a06e37fb73
---
 bin/dbus/cx.ring.Ring.ConfigurationManager.xml |  2 +-
 bin/dbus/dbusconfigurationmanager.hpp          |  2 +-
 bin/jni/configurationmanager.i                 |  4 ++--
 bin/nodejs/configurationmanager.i              |  4 ++--
 src/account.h                                  |  2 +-
 src/client/configurationmanager.cpp            |  2 +-
 src/jami/configurationmanager_interface.h      |  2 +-
 src/jamidht/jamiaccount.cpp                    |  9 +++------
 src/jamidht/jamiaccount.h                      |  2 +-
 src/sip/sipaccount.cpp                         | 10 +++-------
 src/sip/sipaccount.h                           |  2 +-
 11 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml
index 37e3cf65f..d5e99a09c 100644
--- a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml
+++ b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml
@@ -579,7 +579,7 @@
             <arg type="s" name="accountId" direction="in"/>
             <arg type="s" name="displayName" direction="in"/>
             <arg type="s" name="avatar" direction="in"/>
-            <arg type="t" name="flag" direction="in"/>
+            <arg type="i" name="flag" direction="in"/>
             <tp:docstring>
                Update the profile of the account and send it to peers.
                 Flag options :
diff --git a/bin/dbus/dbusconfigurationmanager.hpp b/bin/dbus/dbusconfigurationmanager.hpp
index c50baf7ac..b5d267a67 100644
--- a/bin/dbus/dbusconfigurationmanager.hpp
+++ b/bin/dbus/dbusconfigurationmanager.hpp
@@ -217,7 +217,7 @@ public:
     }
 
     void
-    updateProfile(const std::string& accountID,const std::string& displayName, const std::string& avatar, const uint64_t& flag)
+    updateProfile(const std::string& accountID,const std::string& displayName, const std::string& avatar, const int32_t& flag)
     {
         libjami::updateProfile(accountID, displayName, avatar, flag);
     }
diff --git a/bin/jni/configurationmanager.i b/bin/jni/configurationmanager.i
index 34214d2f3..af6e2a87a 100644
--- a/bin/jni/configurationmanager.i
+++ b/bin/jni/configurationmanager.i
@@ -90,11 +90,11 @@ 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, const uint64_t& flag);
+void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag);
 std::vector<std::string> getAccountList();
 void sendRegister(const std::string& accountId, bool enable);
 void registerAllAccounts(void);
-uint64_t sendAccountTextMessage(const std::string& accountId, const std::string& to, const std::map<std::string, std::string>& message, const int32_t& flag);
+uint64_t sendAccountTextMessage(const std::string& accountId, const std::string& to, const std::map<std::string, std::string>& message, int32_t flag);
 std::vector<libjami::Message> getLastMessages(const std::string& accountId, uint64_t base_timestamp);
 int getMessageStatus(uint64_t id);
 int getMessageStatus(const std::string& accountId, uint64_t id);
diff --git a/bin/nodejs/configurationmanager.i b/bin/nodejs/configurationmanager.i
index c55414e5b..8cc261ee5 100644
--- a/bin/nodejs/configurationmanager.i
+++ b/bin/nodejs/configurationmanager.i
@@ -86,11 +86,11 @@ 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, const uint64_t& flag);
+void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag);
 std::vector<std::string> getAccountList();
 void sendRegister(const std::string& accountId, bool enable);
 void registerAllAccounts(void);
-uint64_t sendAccountTextMessage(const std::string& accountId, const std::string& to, const std::map<std::string, std::string>& message, const int32_t& flag);
+uint64_t sendAccountTextMessage(const std::string& accountId, const std::string& to, const std::map<std::string, std::string>& message, int32_t flag);
 std::vector<libjami::Message> getLastMessages(const std::string& accountId, uint64_t base_timestamp);
 int getMessageStatus(uint64_t id);
 int getMessageStatus(const std::string& accountId, uint64_t id);
diff --git a/src/account.h b/src/account.h
index 0a738f7b3..c38ab4fa4 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*/,const uint64_t& /*flag*/) = 0;
+    virtual void updateProfile(const std::string& /*displayName*/,  const std::string& /*avatar*/, 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 076526e7c..e46ca3db1 100644
--- a/src/client/configurationmanager.cpp
+++ b/src/client/configurationmanager.cpp
@@ -294,7 +294,7 @@ getNearbyPeers(const std::string& accountId)
 }
 
 void
-updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar,const uint64_t& flag)
+updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, int32_t flag)
 {
     if (const auto acc = jami::Manager::instance().getAccount(accountId)){
         acc->updateProfile(displayName, avatar, flag);
diff --git a/src/jami/configurationmanager_interface.h b/src/jami/configurationmanager_interface.h
index 2fc988457..31a08cff6 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, const uint64_t& flag);
+LIBJAMI_PUBLIC void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, 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 8cf817f86..18e91d570 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -3395,7 +3395,7 @@ JamiAccount::sendProfileToPeers()
 void
 JamiAccount::updateProfile(const std::string& displayName,
                            const std::string& avatar,
-                           const uint64_t& flag)
+                           int32_t flag)
 {
     const auto& accountUri = accountManager_->getInfo()->accountId;
     const auto& path = profilePath();
@@ -3411,7 +3411,6 @@ JamiAccount::updateProfile(const std::string& displayName,
     }
 
     const auto& vCardPath = profiles / fmt::format("{}.vcf", base64::encode(accountUri));
-    const std::filesystem::path& tmpPath = vCardPath.string() + ".tmp";
 
     auto profile = getProfileVcard();
     if (profile.empty()) {
@@ -3440,13 +3439,11 @@ JamiAccount::updateProfile(const std::string& displayName,
 
     // nothing happens to the profile photo if the avatarPath is invalid
     // and not empty. So far it seems to be the best default behavior.
-
-    const std::string& vCard = vCard::utils::toString(profile);
-
     try {
+        std::filesystem::path tmpPath = vCardPath.string() + ".tmp";
         std::ofstream file(tmpPath);
         if (file.is_open()) {
-            file << vCard;
+            file << vCard::utils::toString(profile);
             file.close();
             std::filesystem::rename(tmpPath, vCardPath);
             fileutils::createFileLink(path, vCardPath);
diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h
index ca36fa26d..d23221611 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, const uint64_t& flag);
+    void updateProfile(const std::string& displayName, const std::string& avatar, 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 db928c69c..d5778cd98 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -148,7 +148,7 @@ SIPAccount::~SIPAccount() noexcept
 void
 SIPAccount::updateProfile(const std::string& displayName,
                           const std::string& avatar,
-                          const uint64_t& flag)
+                          int32_t flag)
 {
     auto vCardPath = idPath_ / "profile.vcf";
 
@@ -162,8 +162,7 @@ SIPAccount::updateProfile(const std::string& displayName,
         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;
+                profile["PHOTO;ENCODING=BASE64;TYPE=PNG"] = base64::encode(fileutils::loadFile(avatarPath));
             } catch (const std::exception& e) {
                 JAMI_ERROR("Failed to load avatar: {}", e.what());
             }
@@ -176,15 +175,12 @@ SIPAccount::updateProfile(const std::string& displayName,
 
     // nothing happens to the profile photo if the avatarPath is invalid
     // and not empty. So far it seems to be the best default behavior.
-
-    const std::string& vCard = vCard::utils::toString(profile);
-
     try {
         auto tmpPath = vCardPath;
         tmpPath += ".tmp";
         std::ofstream file(tmpPath);
         if (file.is_open()) {
-            file << vCard;
+            file << vCard::utils::toString(profile);
             file.close();
             std::filesystem::rename(tmpPath, vCardPath);
         } else {
diff --git a/src/sip/sipaccount.h b/src/sip/sipaccount.h
index 05cee9a1b..ff7927be0 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, const uint64_t& flag) override;
+    void updateProfile(const std::string& displayName, const std::string& avatar, int32_t flag) override;
 
     /**
      * Initialize the SIP voip link with the account parameters and send registration
-- 
GitLab