summary refs log tree commit diff
path: root/resources/qml
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2021-06-10 20:11:49 -0400
committerLoren Burkholder <computersemiexpert@outlook.com>2021-07-20 21:47:22 -0400
commit6c57fa6c5b491e981958e417458edac40e9000b4 (patch)
treedc4dd84f0ff913866eda5a386e5c367bad685086 /resources/qml
parentQML the room member list (diff)
downloadnheko-6c57fa6c5b491e981958e417458edac40e9000b4.tar.xz
QML the invite dialog
This also adds a property `roomId` to TimelineModel.
Diffstat (limited to 'resources/qml')
-rw-r--r--resources/qml/InviteDialog.qml112
-rw-r--r--resources/qml/TopBar.qml14
-rw-r--r--resources/qml/types/Invitee.qml5
3 files changed, 130 insertions, 1 deletions
diff --git a/resources/qml/InviteDialog.qml b/resources/qml/InviteDialog.qml
new file mode 100644
index 00000000..5d3a8f1e
--- /dev/null
+++ b/resources/qml/InviteDialog.qml
@@ -0,0 +1,112 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+import QtQuick.Layouts 1.12
+import im.nheko 1.0
+import "./types"
+
+ApplicationWindow {
+    id: inviteDialogRoot
+
+    property string roomId
+    property string roomName
+    property list<Invitee> invitees
+
+    function addInvite() {
+        if (inviteeEntry.text.match("@.+?:.{3,}"))
+        {
+            invitees.push(inviteeComponent.createObject(
+                              inviteDialogRoot, {
+                                  "invitee": inviteeEntry.text
+                              }));
+            inviteeEntry.clear();
+        }
+    }
+
+    function accept() {
+        if (inviteeEntry.text !== "")
+            addInvite();
+
+        var inviteeStringList = ["temp"]; // the "temp" element exists to declare this as a string array
+        for (var i = 0; i < invitees.length; ++i)
+            inviteeStringList.push(invitees[i].invitee);
+        inviteeStringList.shift(); // remove the first item
+
+        TimelineManager.inviteUsers(inviteDialogRoot.roomId, inviteeStringList);
+    }
+
+    title: qsTr("Invite users to ") + roomName
+    x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
+    y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
+    height: 380
+    width: 340
+
+    Component {
+        id: inviteeComponent
+
+        Invitee {}
+    }
+
+    // TODO: make this work in the TextField
+    Shortcut {
+        sequence: "Ctrl+Enter"
+        onActivated: inviteDialogRoot.accept()
+    }
+
+    ColumnLayout {
+        anchors.fill: parent
+        anchors.margins: 10
+        spacing: 10
+
+        Label {
+            text: qsTr("User ID to invite")
+            Layout.fillWidth: true
+        }
+
+        RowLayout {
+            spacing: 10
+
+            TextField {
+                id: inviteeEntry
+
+                placeholderText: qsTr("@joe:matrix.org", "Example user id. The name 'joe' can be localized however you want.")
+                Layout.fillWidth: true
+                onAccepted: if (text !== "") addInvite()
+            }
+
+            Button {
+                text: qsTr("Invite")
+                onClicked: if (inviteeEntry.text !== "") addInvite()
+            }
+        }
+
+        ListView {
+            id: inviteesList
+
+            Layout.fillWidth: true
+            Layout.fillHeight: true
+            model: invitees
+            delegate: Label {
+                text: model.invitee
+            }
+        }
+    }
+
+    footer: DialogButtonBox {
+        id: buttons
+
+        Button {
+            text: qsTr("Invite")
+            DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
+            onClicked: {
+                inviteDialogRoot.accept();
+                inviteDialogRoot.close();
+            }
+        }
+
+        Button {
+            text: qsTr("Cancel")
+            DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
+            onClicked: inviteDialogRoot.close();
+        }
+    }
+}
diff --git a/resources/qml/TopBar.qml b/resources/qml/TopBar.qml
index 50c2447c..72dbe604 100644
--- a/resources/qml/TopBar.qml
+++ b/resources/qml/TopBar.qml
@@ -21,6 +21,12 @@ Rectangle {
     z: 3
     color: Nheko.colors.window
 
+    Component {
+        id: inviteDialog
+
+        InviteDialog {}
+    }
+
     TapHandler {
         onSingleTapped: {
             if (room)
@@ -111,7 +117,13 @@ Rectangle {
                 Platform.MenuItem {
                     visible: room ? room.permissions.canInvite() : false
                     text: qsTr("Invite users")
-                    onTriggered: TimelineManager.openInviteUsersDialog()
+                    onTriggered: {
+                        var dialog = inviteDialog.createObject(topBar, {
+                                                      "roomId": room.roomId,
+                                                      "roomName": room.roomName
+                                                  });
+                        dialog.show();
+                    }
                 }
 
                 Platform.MenuItem {
diff --git a/resources/qml/types/Invitee.qml b/resources/qml/types/Invitee.qml
new file mode 100644
index 00000000..fbc0b781
--- /dev/null
+++ b/resources/qml/types/Invitee.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.12
+
+Item {
+    property string invitee
+}