From 5962210088d9d4dde1d547ecbad41919051502c9 Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Thu, 25 Aug 2022 10:24:44 -0400
Subject: [PATCH] conversation: fix ConversationSyncFinished

This patch increase fetched conversation number earlier,
so ConversationSyncFinished would not be emitted in case when
second call to fetchNewCommits happened before receiving callback
from onNeedSocket_.

Change-Id: I72263768426fcce671029fd165323ce89e49e91b
---
 src/jamidht/conversation_module.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp
index 841ded0512..cd0fbae098 100644
--- a/src/jamidht/conversation_module.cpp
+++ b/src/jamidht/conversation_module.cpp
@@ -403,6 +403,7 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
                       conversationId.c_str());
             return;
         }
+        syncCnt.fetch_add(1);
         onNeedSocket_(conversationId,
                       deviceId,
                       [this,
@@ -416,10 +417,10 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
                               || !conversation->second) {
                               std::lock_guard<std::mutex> lk(pendingConversationsFetchMtx_);
                               stopFetch(conversationId, deviceId);
+                              syncCnt.fetch_sub(1);
                               return false;
                           }
                           acc->addGitSocket(channel->deviceId(), conversationId, channel);
-                          syncCnt.fetch_add(1);
                           conversation->second->sync(
                               peer,
                               deviceId,
-- 
GitLab