From a28c88becce9fc87da3ef46561c3da46ba1c1c88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 12 Nov 2021 11:21:03 -0500
Subject: [PATCH] conversationlistmodel: use removeConversation for swarm

Also, dataForItem MUST return a QVariant to be able to show the
context menu

Change-Id: Ia02a087e0eb3d55000cb2026d41c8fb53e8ae46c
---
 src/conversationlistmodelbase.cpp              |  6 +++---
 .../components/ConversationListView.qml        |  2 ++
 .../ConversationSmartListContextMenu.qml       | 18 ++++++++++++++----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/conversationlistmodelbase.cpp b/src/conversationlistmodelbase.cpp
index 98df36e13..db577fc40 100644
--- a/src/conversationlistmodelbase.cpp
+++ b/src/conversationlistmodelbase.cpp
@@ -163,12 +163,12 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
         auto peerUri = peerUriList.at(0);
         ContactModel* contactModel;
         contact::Info contact {};
+        contactModel = lrcInstance_->getCurrentAccountInfo().contactModel.get();
         try {
-            contactModel = lrcInstance_->getCurrentAccountInfo().contactModel.get();
             contact = contactModel->getContact(peerUri);
         } catch (const std::exception&) {
-            qWarning() << Q_FUNC_INFO << "Can't find contact" << peerUri;
-            return {};
+            qWarning() << Q_FUNC_INFO << "Can't find contact" << peerUri
+                       << " this is a bug, please report";
         }
 
         switch (role) {
diff --git a/src/mainview/components/ConversationListView.qml b/src/mainview/components/ConversationListView.qml
index f990f5d25..cae64a224 100644
--- a/src/mainview/components/ConversationListView.qml
+++ b/src/mainview/components/ConversationListView.qml
@@ -133,12 +133,14 @@ ListView {
                 "title": model.dataForRow(row, ConversationList.Title),
                 "uri": model.dataForRow(row, ConversationList.URI),
                 "isSwarm": model.dataForRow(row, ConversationList.IsSwarm),
+                "mode": model.dataForRow(row, ConversationList.Mode),
                 "readOnly": model.dataForRow(row, ConversationList.ReadOnly)
             }
 
             responsibleAccountId = LRCInstance.currentAccountId
             responsibleConvUid = item.convId
             isSwarm = item.isSwarm
+            mode = item.mode
             contactType = LRCInstance.currentAccountType
             readOnly = item.readOnly
 
diff --git a/src/mainview/components/ConversationSmartListContextMenu.qml b/src/mainview/components/ConversationSmartListContextMenu.qml
index 2a26f0a3c..7530d56c0 100644
--- a/src/mainview/components/ConversationSmartListContextMenu.qml
+++ b/src/mainview/components/ConversationSmartListContextMenu.qml
@@ -31,6 +31,7 @@ ContextMenuAutoLoader {
     property string responsibleAccountId: ""
     property string responsibleConvUid: ""
     property bool isSwarm: false
+    property var mode: undefined
     property int contactType: Profile.Type.INVALID
     property bool hasCall: {
         if (responsibleAccountId && responsibleConvUid)
@@ -79,11 +80,20 @@ ContextMenuAutoLoader {
         GeneralMenuItem {
             id: removeContact
 
-            canTrigger: !hasCall && (contactType === Profile.Type.JAMI
-                                     || contactType === Profile.Type.SIP)
-            itemName: JamiStrings.removeContact
+            canTrigger: !hasCall
+            itemName: {
+                if (mode !== Conversation.Mode.ONE_TO_ONE && mode !== Conversation.Mode.NON_SWARM)
+                    return JamiStrings.removeConversation
+                else
+                    return JamiStrings.removeContact
+            }
             iconSource: JamiResources.ic_hangup_participant_24dp_svg
-            onClicked: MessagesAdapter.removeContact(responsibleConvUid)
+            onClicked: {
+                if (isSwarm)
+                    MessagesAdapter.removeConversation(responsibleConvUid)
+                else
+                    MessagesAdapter.removeContact(responsibleConvUid)
+            }
         },
         GeneralMenuItem {
             id: hangup
-- 
GitLab