From b88f4ccd4757b0ce522cacc3af3d02479cc6e793 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 2 Aug 2021 14:00:12 -0400
Subject: [PATCH] jamiaccount: sync conversations when we're ready to receives
 clone

As soon as a device detects a new conversation it will try to clone
the conversation from this device. So, announce conversation when
the repository is cloned.

Change-Id: I921b6685967709bd8f3675508b57478dc4589edf
GitLab: https://git.jami.net/savoirfairelinux/ring-project/-/issues/1282
---
 src/jamidht/jamiaccount.cpp               | 3 ++-
 src/jamidht/multiplexed_socket.cpp        | 3 ++-
 test/unitTest/syncHistory/syncHistory.cpp | 5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 7e93f0711c..7b0131dc3c 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -3785,7 +3785,6 @@ JamiAccount::acceptConversationRequest(const std::string& conversationId)
         if (auto shared = w.lock())
             shared->addNewConversation(info);
     });
-    syncWithConnected();
     checkConversationsEvents();
 }
 
@@ -3862,6 +3861,8 @@ JamiAccount::handlePendingConversations()
                         // Inform user that the conversation is ready
                         emitSignal<DRing::ConversationSignal::ConversationReady>(shared->accountID_,
                                                                                  conversationId);
+                        shared
+                            ->syncWithConnected(); // This informs other devices to clone the conversation
                     }
                 } catch (const std::exception& e) {
                     emitSignal<DRing::ConversationSignal::OnConversationError>(shared->accountID_,
diff --git a/src/jamidht/multiplexed_socket.cpp b/src/jamidht/multiplexed_socket.cpp
index cd3c3d00be..901a36fb75 100644
--- a/src/jamidht/multiplexed_socket.cpp
+++ b/src/jamidht/multiplexed_socket.cpp
@@ -125,7 +125,8 @@ public:
             channelSocket = std::make_shared<ChannelSocket>(parent_.weak(), name, channel);
         else {
             JAMI_WARN("A channel is already present on that socket, accepting "
-                      "the request will close the previous one");
+                      "the request will close the previous one %s",
+                      name.c_str());
         }
         return channelSocket;
     }
diff --git a/test/unitTest/syncHistory/syncHistory.cpp b/test/unitTest/syncHistory/syncHistory.cpp
index be8e461671..7608518ab1 100644
--- a/test/unitTest/syncHistory/syncHistory.cpp
+++ b/test/unitTest/syncHistory/syncHistory.cpp
@@ -154,6 +154,7 @@ SyncHistoryTest::testCreateConversationThenSync()
         return alice2Ready && conversationReady;
     }));
     std::remove(aliceArchive.c_str());
+    DRing::unregisterSignalHandlers();
 }
 
 void
@@ -597,6 +598,7 @@ SyncHistoryTest::testSyncCreateAccountExportDeleteReimportOldBackup()
     aliceAccount->sendMessage(convId, std::string("hi"));
     cv.wait_for(lk, std::chrono::seconds(30), [&]() { return messageBobReceived == 1; });
     std::remove(aliceArchive.c_str());
+    DRing::unregisterSignalHandlers();
 }
 
 void
@@ -710,6 +712,7 @@ SyncHistoryTest::testSyncCreateAccountExportDeleteReimportWithConvId()
     aliceAccount->sendMessage(convId, std::string("hi"));
     cv.wait_for(lk, std::chrono::seconds(30), [&]() { return messageBobReceived == 1; });
     std::remove(aliceArchive.c_str());
+    DRing::unregisterSignalHandlers();
 }
 
 void
@@ -806,6 +809,7 @@ SyncHistoryTest::testSyncCreateAccountExportDeleteReimportWithConvReq()
         return conversationReady && messageBobReceived == 1;
     }));
     std::remove(aliceArchive.c_str());
+    DRing::unregisterSignalHandlers();
 }
 
 void
@@ -862,6 +866,7 @@ SyncHistoryTest::testSyncOneToOne()
         return alice2Ready && conversationReady;
     }));
     std::remove(aliceArchive.c_str());
+    DRing::unregisterSignalHandlers();
 }
 
 void
-- 
GitLab