From e8166f34331c320bf82f96cb9946852215367998 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 29 Apr 2023 17:13:24 +0000 Subject: [PATCH] Improve Invitation Flow - Update the conatainsUser function to use memberState so that invites do not show up as being in the leave state. - Update the InviteUser page to use Kirigami.BasicListItem and make the invite button remain visible but be untoggleable when the if user has already been invited. closes network/neochat#202 --- src/neochatroom.cpp | 4 ++ src/qml/Page/InviteUserPage.qml | 73 +++++++++++---------------------- 2 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index fe28b6ebc..50c6ca271 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -920,6 +920,9 @@ void NeoChatRoom::toggleReaction(const QString &eventId, const QString &reaction bool NeoChatRoom::containsUser(const QString &userID) const { +#ifdef QUOTIENT_07 + return memberState(userID) != Membership::Leave; +#else auto u = Room::user(userID); if (!u) { @@ -927,6 +930,7 @@ bool NeoChatRoom::containsUser(const QString &userID) const } return Room::memberJoinState(u) != JoinState::Leave; +#endif } bool NeoChatRoom::canSendEvent(const QString &eventType) const diff --git a/src/qml/Page/InviteUserPage.qml b/src/qml/Page/InviteUserPage.qml index 4c68217c8..2300c72bd 100644 --- a/src/qml/Page/InviteUserPage.qml +++ b/src/qml/Page/InviteUserPage.qml @@ -49,9 +49,6 @@ Kirigami.ScrollablePage { } ListView { - Layout.fillWidth: true - Layout.fillHeight: true - id: userDictListView clip: true @@ -71,60 +68,38 @@ Kirigami.ScrollablePage { text: i18n("No users available") } - delegate: Kirigami.AbstractListItem { + delegate: Kirigami.BasicListItem { id: delegate property bool inRoom: room && room.containsUser(userID) - topPadding: Kirigami.Units.largeSpacing - bottomPadding: Kirigami.Units.largeSpacing + label: model.name + subtitle: model.userID - contentItem: RowLayout { - Kirigami.Avatar { - Layout.preferredWidth: height - Layout.fillHeight: true + leading: Kirigami.Avatar { + implicitWidth: height + source: model.avatar ? ("image://mxc/" + model.avatar) : "" + name: model.name + } + trailing: QQC2.ToolButton { + id: inviteButton + icon.name: "document-send" + text: i18n("Send invitation") + checkable: true + checked: inRoom + opacity: inRoom ? 0.5 : 1 - source: model.avatar ? ("image://mxc/" + model.avatar) : "" - name: model.name - } - - ColumnLayout { - Layout.fillWidth: true - Layout.fillHeight: true - - spacing: 0 - - Kirigami.Heading { - Layout.fillWidth: true - Layout.fillHeight: true - level: 3 - - text: name - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - - QQC2.Label { - Layout.fillWidth: true - Layout.fillHeight: true - - text: userID - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap - } - } - - QQC2.ToolButton { - visible: !inRoom - icon.name: "document-send" - text: i18n("Send invitation") - - onClicked: { - room.inviteToRoom(userID); + onToggled: { + if (inRoom) { + checked = true + } else { + room.inviteToRoom(model.userID); applicationWindow().pageStack.layers.pop(); } } + + QQC2.ToolTip.text: !inRoom ? text : i18n("User is either already a member or has been invited") + QQC2.ToolTip.visible: inviteButton.hovered + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay } } }