From 1c68d4f9998333a897dd43968b7fbb13690f6ed6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 20 Dec 2023 15:37:09 -0500
Subject: [PATCH] conversation: move sendProfile

The problem with the previous method is that it was only sent one
side at the clone. At least, here we know that  both sides are connected
and in the same conversation.

Change-Id: I37bd5f921ad798a259c3262060e1158e58394697
---
 src/jamidht/conversation.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp
index 9d03d56e26..629c115d83 100644
--- a/src/jamidht/conversation.cpp
+++ b/src/jamidht/conversation.cpp
@@ -1372,7 +1372,6 @@ Conversation::sync(const std::string& member,
                     start = 0;
                 sthis->downloadFile(wr.interactionId, wr.fileId, wr.path, member, deviceId, start);
             }
-            account->sendProfile(sthis->id(), member, deviceId);
         }
     });
 }
@@ -1954,7 +1953,22 @@ Conversation::onNeedSocket(NeedSocketCb needSocket)
 void
 Conversation::addSwarmChannel(std::shared_ptr<dhtnet::ChannelSocket> channel)
 {
+    auto deviceId = channel->deviceId();
+    // Transmit avatar if necessary
+    // We do this here, because at this point we know both sides are connected and in
+    // the same conversation
+    // addSwarmChannel is a bit more complex, but it should be the best moment to do this.
+    auto cert = channel->peerCertificate();
+    if (!cert || !cert->issuer)
+        return;
+    auto member = cert->issuer->getId().toString();
     pimpl_->swarmManager_->addChannel(std::move(channel));
+    dht::ThreadPool::io().run([member, deviceId, a = pimpl_->account_, w=weak_from_this()]{
+        auto sthis = w.lock();
+        if (auto account = a.lock()) {
+            account->sendProfile(sthis->id(), member, deviceId.toString());
+        }
+    });
 }
 
 uint32_t
-- 
GitLab