From d9432163f654d79cd06847aef2584908bc26857d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 15 Jul 2022 15:26:17 -0400
Subject: [PATCH] conversationmodel: let the daemon manage the removal

Change-Id: I00e8fd2552aa1e08c03ef8e7dada4629ebdd619d
---
 src/libclient/conversationmodel.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/libclient/conversationmodel.cpp b/src/libclient/conversationmodel.cpp
index cdaef0240..3c7429619 100644
--- a/src/libclient/conversationmodel.cpp
+++ b/src/libclient/conversationmodel.cpp
@@ -2580,25 +2580,27 @@ ConversationModelPimpl::slotConversationRemoved(const QString& accountId,
         } catch (...) {
         }
 
+        removeConversation();
+
         if (conversation.mode == conversation::Mode::ONE_TO_ONE) {
-            removeConversation();
 
             // If it's a 1:1 conversation and we don't have any more conversation
             // we can remove the contact
-            auto conv = storage::getConversationsWithPeer(db, contactUri);
-            if (conv.empty())
-                linked.owner.contactModel->removeContact(contactUri, false);
+            auto contactRemoved = true;
+            try {
+                auto& conv = getConversationForPeerUri(contactUri).get();
+                contactRemoved = !conv.isSwarm();
+            } catch (...) {}
 
-            if (contact.isBanned && conv.empty()) {
+            if (contact.isBanned && contactRemoved) {
                 // Add 1:1 conv for banned
                 auto c = storage::beginConversationWithPeer(db, contactUri);
                 addConversationWith(c, contactUri, false);
                 Q_EMIT linked.conversationReady(c, contactUri);
                 Q_EMIT linked.newConversation(c);
             }
-        } else {
-            removeConversation();
         }
+
     } catch (const std::exception& e) {
         qWarning() << e.what();
     }
-- 
GitLab