From 24d401365e8f83c207b9381e59cb0a6ac9e24b1c Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 25 Feb 2023 23:19:15 -0500 Subject: [PATCH] Always open the invite dialog properly from the member list --- resources/qml/Root.qml | 2 -- resources/qml/dialogs/InviteDialog.qml | 4 +--- src/InviteesModel.cpp | 5 +++-- src/InviteesModel.h | 8 +++++++- src/timeline/TimelineViewManager.cpp | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index d0a8f2e8..9584eb8d 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -268,8 +268,6 @@ Pane { var component = Qt.createComponent("qrc:/qml/dialogs/InviteDialog.qml") if (component.status == Component.Ready) { var dialog = component.createObject(timelineRoot, { - "roomId": Rooms.currentRoom.roomId, - "plainRoomName": Rooms.currentRoom.plainRoomName, "invitees": invitees }); dialog.show(); diff --git a/resources/qml/dialogs/InviteDialog.qml b/resources/qml/dialogs/InviteDialog.qml index ee555795..b142818d 100644 --- a/resources/qml/dialogs/InviteDialog.qml +++ b/resources/qml/dialogs/InviteDialog.qml @@ -12,8 +12,6 @@ import im.nheko 1.0 ApplicationWindow { id: inviteDialogRoot - property string roomId - property string plainRoomName property InviteesModel invitees property var friendsCompleter property var profile @@ -39,7 +37,7 @@ ApplicationWindow { close(); } - title: qsTr("Invite users to %1").arg(plainRoomName) + title: qsTr("Invite users to %1").arg(invitees.room.plainRoomName) height: 380 width: 340 palette: Nheko.colors diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 2b95a36f..7e4f4e8b 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -9,8 +9,9 @@ #include "MatrixClient.h" #include "mtx/responses/profile.hpp" -InviteesModel::InviteesModel(QObject *parent) - : QAbstractListModel{parent} +InviteesModel::InviteesModel(TimelineModel *room, QObject *parent) + : QAbstractListModel{parent}, + room_{room} { } diff --git a/src/InviteesModel.h b/src/InviteesModel.h index 8fe8fc22..66811838 100644 --- a/src/InviteesModel.h +++ b/src/InviteesModel.h @@ -8,6 +8,8 @@ #include #include +class TimelineModel; + class Invitee final : public QObject { Q_OBJECT @@ -34,6 +36,7 @@ class InviteesModel final : public QAbstractListModel Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + Q_PROPERTY(TimelineModel * room READ room CONSTANT) public: enum Roles @@ -43,7 +46,9 @@ public: AvatarUrl, }; - InviteesModel(QObject *parent = nullptr); + InviteesModel(TimelineModel *room, QObject *parent = nullptr); + + TimelineModel *room() const { return room_; } Q_INVOKABLE void addUser(QString mxid, QString displayName = "", QString avatarUrl = ""); Q_INVOKABLE void removeUser(QString mxid); @@ -63,6 +68,7 @@ signals: private: QVector invitees_; + TimelineModel *room_; }; #endif // INVITEESMODEL_H diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index cdcc689d..c19d0c3f 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -180,7 +180,7 @@ TimelineViewManager::openRoomSettings(QString room_id) void TimelineViewManager::openInviteUsers(QString roomId) { - InviteesModel *model = new InviteesModel{}; + InviteesModel *model = new InviteesModel{rooms_->getRoomById(roomId).data()}; connect(model, &InviteesModel::accept, this, [this, model, roomId]() { emit inviteUsers(roomId, model->mxids()); });