From b1c1274d96144805bf416571117f9889f2e55600 Mon Sep 17 00:00:00 2001
From: Loren Burkholder <computersemiexpert@outlook.com>
Date: Sat, 13 Nov 2021 15:05:26 -0500
Subject: [PATCH] Allow removing users from the invite dialog

---
 resources/qml/dialogs/InviteDialog.qml | 17 ++++++++++++++---
 src/InviteesModel.cpp                  | 14 ++++++++++++++
 src/InviteesModel.h                    |  1 +
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/resources/qml/dialogs/InviteDialog.qml b/resources/qml/dialogs/InviteDialog.qml
index 168819c48..6ee6fbf5c 100644
--- a/resources/qml/dialogs/InviteDialog.qml
+++ b/resources/qml/dialogs/InviteDialog.qml
@@ -116,6 +116,7 @@ ApplicationWindow {
                     spacing: Nheko.paddingMedium
                     anchors.verticalCenter: parent.verticalCenter
                     x: parent.x + Nheko.paddingSmall
+                    width: del.width - Nheko.paddingSmall * 2
 
                     Avatar {
                         width: Nheko.avatarSize
@@ -148,11 +149,21 @@ ApplicationWindow {
 
                     }
 
-                    CursorShape {
-                        anchors.fill: parent
-                        cursorShape: Qt.PointingHandCursor
+                    Item {
+                        Layout.fillWidth: true
+                        Layout.fillHeight: true
                     }
 
+                    ImageButton {
+                        image: ":/icons/icons/ui/remove-symbol.png"
+                        onClicked: invitees.removeUser(model.mxid)
+                    }
+
+                }
+
+                CursorShape {
+                    anchors.fill: parent
+                    cursorShape: Qt.PointingHandCursor
                 }
 
             }
diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp
index e045581a9..707bfd97e 100644
--- a/src/InviteesModel.cpp
+++ b/src/InviteesModel.cpp
@@ -30,6 +30,20 @@ InviteesModel::addUser(QString mxid)
     emit countChanged();
 }
 
+void
+InviteesModel::removeUser(QString mxid)
+{
+    for (int i = 0; i < invitees_.length(); ++i) {
+        if (invitees_[i]->mxid_ == mxid) {
+            beginRemoveRows(QModelIndex(), i, i);
+            invitees_.removeAt(i);
+            endRemoveRows();
+            emit countChanged();
+            break;
+        }
+    }
+}
+
 QHash<int, QByteArray>
 InviteesModel::roleNames() const
 {
diff --git a/src/InviteesModel.h b/src/InviteesModel.h
index fd64116b3..65fb78d6b 100644
--- a/src/InviteesModel.h
+++ b/src/InviteesModel.h
@@ -43,6 +43,7 @@ public:
     InviteesModel(QObject *parent = nullptr);
 
     Q_INVOKABLE void addUser(QString mxid);
+    Q_INVOKABLE void removeUser(QString mxid);
 
     QHash<int, QByteArray> roleNames() const override;
     int rowCount(const QModelIndex & = QModelIndex()) const override
-- 
GitLab