From 7b1fd8a3fe1465fb606f0da6eb911586ca434229 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 27 Aug 2021 16:54:00 -0400
Subject: [PATCH] chatviewheader: prepare interface for small groups

GitLab: #340
Change-Id: Ic3fe3c6d317f2af485b79414242e7be86d5f820d
---
 src/contactadapter.cpp                     | 22 +++++++++++++++-
 src/mainview/components/ChatViewHeader.qml | 29 +++++++++++++++++++---
 src/mainview/components/ContactPicker.qml  |  2 ++
 src/smartlistmodel.cpp                     |  3 ++-
 src/smartlistmodel.h                       |  2 +-
 5 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/src/contactadapter.cpp b/src/contactadapter.cpp
index 1638d8344..534ba666b 100644
--- a/src/contactadapter.cpp
+++ b/src/contactadapter.cpp
@@ -54,7 +54,11 @@ ContactAdapter::getContactSelectableModel(int type)
                 return !defaultModerators_.contains(index.data(Role::URI).toString());
             });
         break;
-
+    case SmartListModel::Type::ADDCONVMEMBER:
+        selectableProxyModel_->setPredicate([](const QModelIndex& index, const QRegExp&) {
+            return index.data(Role::IsCoreDialog).toBool();
+        });
+        break;
     case SmartListModel::Type::CONFERENCE:
         selectableProxyModel_->setPredicate([](const QModelIndex& index, const QRegularExpression&) {
             return index.data(Role::Presence).toBool();
@@ -102,6 +106,16 @@ ContactAdapter::setSearchFilter(const QString& filter)
                 return (!defaultModerators_.contains(index.data(Role::URI).toString())
                         && index.data(Role::Title).toString().contains(filter));
             });
+    } else if (listModeltype_ == SmartListModel::Type::ADDCONVMEMBER) {
+        selectableProxyModel_->setPredicate(
+            [this, filter](const QModelIndex& index, const QRegExp&) {
+                return (index.data(Role::Title).toString().contains(filter, Qt::CaseInsensitive)
+                        || index.data(Role::RegisteredName)
+                               .toString()
+                               .contains(filter, Qt::CaseInsensitive)
+                        || index.data(Role::URI).toString().contains(filter, Qt::CaseInsensitive))
+                       && index.data(Role::IsCoreDialog).toBool();
+            });
     }
     selectableProxyModel_->setFilterRegularExpression(
         QRegularExpression(filter, QRegularExpression::CaseInsensitiveOption));
@@ -112,10 +126,16 @@ ContactAdapter::contactSelected(int index)
 {
     auto contactIndex = selectableProxyModel_->index(index, 0);
     auto* callModel = lrcInstance_->getCurrentCallModel();
+    auto* convModel = lrcInstance_->getCurrentConversationModel();
     const auto& convInfo = lrcInstance_->getConversationFromConvUid(
         lrcInstance_->get_selectedConvUid());
     if (contactIndex.isValid()) {
         switch (listModeltype_) {
+        case SmartListModel::Type::ADDCONVMEMBER: {
+            const auto uri = contactIndex.data(Role::URI).value<QString>();
+            convModel->addConversationMember(lrcInstance_->get_selectedConvUid(), uri);
+            break;
+        }
         case SmartListModel::Type::CONFERENCE: {
             // Conference.
             const auto sectionName = contactIndex.data(Role::SectionName).value<QString>();
diff --git a/src/mainview/components/ChatViewHeader.qml b/src/mainview/components/ChatViewHeader.qml
index 9bd11a6c5..50053eea6 100644
--- a/src/mainview/components/ChatViewHeader.qml
+++ b/src/mainview/components/ChatViewHeader.qml
@@ -25,6 +25,7 @@ import net.jami.Constants 1.1
 import net.jami.Adapters 1.1
 
 import "../../commoncomponents"
+import "../js/contactpickercreation.js" as ContactPickerCreation
 
 Rectangle {
     id: root
@@ -49,8 +50,17 @@ Rectangle {
         return true
     }
 
+    property bool addMemberVisibility: {
+        return !CurrentConversation.isCoreDialog && CurrentConversation.isSwarm
+    }
+
     color: JamiTheme.chatviewBgColor
 
+    function addToConversationClicked() {
+        ContactPickerCreation.createContactPickerObjects(ContactList.ADDCONVMEMBER, root)
+        ContactPickerCreation.openContactPicker()
+    }
+
     RowLayout {
         id: messagingHeaderRectRowLayout
 
@@ -140,7 +150,7 @@ Rectangle {
             PushButton {
                 id: startAAudioCallButton
 
-                visible: interactionButtonsVisibility
+                visible: interactionButtonsVisibility && !addMemberVisibility
 
                 source: JamiResources.place_audiocall_24dp_svg
                 toolTipText: JamiStrings.placeAudioCall
@@ -154,8 +164,7 @@ Rectangle {
             PushButton {
                 id: startAVideoCallButton
 
-                visible: CurrentAccount.videoEnabled_Video && interactionButtonsVisibility
-
+                visible: CurrentAccount.videoEnabled_Video && interactionButtonsVisibility && !addMemberVisibility
                 source: JamiResources.videocam_24dp_svg
                 toolTipText: JamiStrings.placeVideoCall
 
@@ -167,6 +176,20 @@ Rectangle {
                 }
             }
 
+            PushButton {
+                id: addParticipantsButton
+
+                visible: addMemberVisibility
+
+                source: JamiResources.add_people_24dp_svg
+                toolTipText: JamiStrings.addParticipants
+
+                normalColor: JamiTheme.chatviewBgColor
+                imageColor: JamiTheme.chatviewButtonColor
+
+                onClicked: root.addToConversationClicked()
+            }
+
             PushButton {
                 id: selectPluginButton
 
diff --git a/src/mainview/components/ContactPicker.qml b/src/mainview/components/ContactPicker.qml
index a5e450b4a..66c52ce1e 100644
--- a/src/mainview/components/ContactPicker.qml
+++ b/src/mainview/components/ContactPicker.qml
@@ -82,6 +82,8 @@ Popup {
                     switch(type) {
                     case ContactList.CONFERENCE:
                         return qsTr("Add to conference")
+                    case ContactList.ADDCONVMEMBER:
+                        return qsTr("Add to conversation")
                     case ContactList.TRANSFER:
                         return qsTr("Transfer this call")
                     default:
diff --git a/src/smartlistmodel.cpp b/src/smartlistmodel.cpp
index 9e52557dd..c07abeba4 100644
--- a/src/smartlistmodel.cpp
+++ b/src/smartlistmodel.cpp
@@ -39,7 +39,7 @@ SmartListModel::SmartListModel(QObject* parent,
 {
     if (listModelType_ == Type::CONFERENCE) {
         setConferenceableFilter();
-    } else if (listModelType_ == Type::CONVERSATION) {
+    } else if (listModelType_ == Type::CONVERSATION || listModelType_ == Type::ADDCONVMEMBER) {
         fillConversationsList();
     }
 }
@@ -131,6 +131,7 @@ SmartListModel::data(const QModelIndex& index, int role) const
         auto& item = lrcInstance_->getConversationFromConvUid(itemConvUid, itemAccountId);
         return dataForItem(item, role);
     } break;
+    case Type::ADDCONVMEMBER:
     case Type::CONVERSATION: {
         auto& item = conversations_.at(index.row());
         return dataForItem(item, role);
diff --git a/src/smartlistmodel.h b/src/smartlistmodel.h
index 642c90b9b..630f10351 100644
--- a/src/smartlistmodel.h
+++ b/src/smartlistmodel.h
@@ -24,7 +24,7 @@
 
 namespace ContactList {
 Q_NAMESPACE
-enum Type { CONVERSATION, CONFERENCE, TRANSFER, COUNT__ };
+enum Type { CONVERSATION, CONFERENCE, TRANSFER, ADDCONVMEMBER, COUNT__ };
 Q_ENUM_NS(Type)
 } // namespace ContactList
 
-- 
GitLab