From f1661d585e46305e3f945f1a160067028f9328ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?=
 <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Date: Thu, 21 Nov 2024 16:10:10 -0500
Subject: [PATCH] conversation_module: only ask for invite if needed

GitLab: #1081
Change-Id: I3ac3468e8ff5b41250a76ab7f40b6ca0e7331f09
---
 src/jamidht/conversation_module.cpp | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp
index 53fcb8748..22da9796b 100644
--- a/src/jamidht/conversation_module.cpp
+++ b/src/jamidht/conversation_module.cpp
@@ -582,13 +582,18 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
 
     auto conv = getConversation(conversationId);
     if (!conv) {
-        JAMI_WARNING("[Account {}] Unable to find conversation {}, ask for an invite",
-                     accountId_,
-                     conversationId);
-        sendMsgCb_(peer,
-                   {},
-                   std::map<std::string, std::string> {{MIME_TYPE_INVITE, conversationId}},
-                   0);
+        if (oldReq == std::nullopt) {
+            // We didn't find a conversation or a request with the given ID.
+            // This suggests that someone tried to send us an invitation but
+            // that we didn't receive it, so we ask for a new one.
+            JAMI_WARNING("[Account {}] Unable to find conversation {}, ask for an invite",
+                         accountId_,
+                         conversationId);
+            sendMsgCb_(peer,
+                       {},
+                       std::map<std::string, std::string> {{MIME_TYPE_INVITE, conversationId}},
+                       0);
+        }
         return;
     }
     std::unique_lock lk(conv->mtx);
-- 
GitLab