From bfd99df345c5bf6f679b3adc0f9575ba22c6af43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 5 Aug 2021 09:55:55 -0400 Subject: [PATCH] jamiaccount: getOneToOne should only return active conversation Change-Id: Id28de65bc265c0001c1e8479c6f4c36b38fae3a7 GitLab: https://git.jami.net/savoirfairelinux/ring-project/-/issues/1282 --- src/jamidht/jamiaccount.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 7b0131dc3c..d4f8199277 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -3832,8 +3832,8 @@ JamiAccount::handlePendingConversations() auto removeRepo = false; { std::lock_guard<std::mutex> lk(shared->conversationsMtx_); - // Note: a removeContact while cloning. In this case, the conversation must - // not be announced and removed. + // Note: a removeContact while cloning. In this case, the conversation + // must not be announced and removed. auto& ci = info->conversations; auto itConv = ci.find(conversationId); if (itConv != ci.end() && itConv->second.removed) @@ -5289,25 +5289,10 @@ JamiAccount::sendMessageNotification(const Conversation& conversation, std::string JamiAccount::getOneToOneConversation(const std::string& uri) const { - auto isSelf = uri == getUsername(); - std::lock_guard<std::mutex> lk(conversationsMtx_); - for (const auto& [key, conv] : conversations_) { - // Note it's important to check getUsername(), else - // removing self can remove all conversations - if (!conv) - continue; - try { - if (conv->mode() == ConversationMode::ONE_TO_ONE) { - auto initMembers = conv->getInitialMembers(); - if (isSelf && initMembers.size() == 1) - return key; - if (std::find(initMembers.begin(), initMembers.end(), uri) != initMembers.end()) - return key; - } - } catch (const std::exception& e) { - JAMI_ERR() << e.what(); - } - } + auto details = getContactDetails(uri); + auto it = details.find(DRing::Account::TrustRequest::CONVERSATIONID); + if (it != details.end()) + return it->second; return {}; } -- GitLab