From 1c867dbbc292a6cc5624f0d8f4ae72603a105b3c Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sun, 23 Jul 2023 18:04:28 -0400 Subject: [PATCH 1/2] Show an indicator in the timeline for mods and admins --- CMakeLists.txt | 1 + resources/qml/MessageView.qml | 9 ++++ .../qml/components/PowerlevelIndicator.qml | 42 +++++++++++++++++++ resources/qml/dialogs/RoomMembers.qml | 37 ++-------------- src/timeline/TimelineModel.cpp | 9 ++++ src/timeline/TimelineModel.h | 1 + 6 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 resources/qml/components/PowerlevelIndicator.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 333e52ad..a82d7432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -731,6 +731,7 @@ set(QML_SOURCES resources/qml/components/MainWindowDialog.qml resources/qml/components/NhekoTabButton.qml resources/qml/components/NotificationBubble.qml + resources/qml/components/PowerlevelIndicator.qml resources/qml/components/ReorderableListview.qml resources/qml/components/SpaceMenuLevel.qml resources/qml/components/TextButton.qml diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index af3a3371..5768a7a6 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -100,6 +100,7 @@ Item { required property string url required property string userId required property string userName + required property int userPowerlevel ListView.delayRemove: true anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined @@ -119,6 +120,7 @@ Item { property date timestamp: wrapper.timestamp property string userId: wrapper.userId property string userName: wrapper.userName + property int userPowerlevel: wrapper.userPowerlevel active: previousMessageUserId !== userId || previousMessageDay !== day || previousMessageIsStateEvent !== isStateEvent //asynchronous: true @@ -625,6 +627,13 @@ Item { target: Presence } } + + PowerlevelIndicator { + Layout.alignment: Qt.AlignVCenter + powerlevel: userPowerlevel + permissions: room ? room.permissions : null + visible: isAdmin || isModerator + } } } } diff --git a/resources/qml/components/PowerlevelIndicator.qml b/resources/qml/components/PowerlevelIndicator.qml new file mode 100644 index 00000000..4b826284 --- /dev/null +++ b/resources/qml/components/PowerlevelIndicator.qml @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import QtQuick +import QtQuick.Controls +import im.nheko + +Image { + required property int powerlevel + required property var permissions + + readonly property bool isAdmin: permissions ? permissions.changeLevel(MtxEvent.PowerLevels) <= powerlevel : false + readonly property bool isModerator: permissions ? permissions.redactLevel() <= powerlevel : false + readonly property bool isDefault: permissions ? permissions.defaultLevel() <= powerlevel : false + + readonly property string sourceUrl: { + if (isAdmin) + return "image://colorimage/:/icons/icons/ui/ribbon_star.svg?"; + else if (isModerator) + return "image://colorimage/:/icons/icons/ui/ribbon.svg?"; + else + return "image://colorimage/:/icons/icons/ui/person.svg?"; + } + + sourceSize.width: 16 + sourceSize.height: 16 + source: sourceUrl + (ma.hovered ? palette.highlight : palette.buttonText) + ToolTip.visible: ma.hovered + ToolTip.text: { + if (isAdmin) + return qsTr("Administrator: %1").arg(powerlevel); + else if (isModerator) + return qsTr("Moderator: %1").arg(powerlevel); + else + return qsTr("User: %1").arg(powerlevel); + } + + HoverHandler { + id: ma + } +} diff --git a/resources/qml/dialogs/RoomMembers.qml b/resources/qml/dialogs/RoomMembers.qml index bbf1605d..64f21381 100644 --- a/resources/qml/dialogs/RoomMembers.qml +++ b/resources/qml/dialogs/RoomMembers.qml @@ -4,6 +4,7 @@ import ".." import "../ui" +import "../components" import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 @@ -159,39 +160,9 @@ ApplicationWindow { } - Image { - property bool isAdmin: room.permissions.changeLevel(MtxEvent.PowerLevels) <= model.powerlevel - property bool isModerator: room.permissions.redactLevel() <= model.powerlevel - //property bool isDefault: room.permissions.defaultLevel() <= model.powerlevel - - property string sourceUrl: { - if (isAdmin) - return "image://colorimage/:/icons/icons/ui/ribbon_star.svg?"; - else if (isModerator) - return "image://colorimage/:/icons/icons/ui/ribbon.svg?"; - else - return "image://colorimage/:/icons/icons/ui/person.svg?"; - } - - Layout.preferredWidth: 16 - Layout.preferredHeight: 16 - sourceSize.width: width - sourceSize.height: height - source: sourceUrl + (ma.hovered ? palette.highlight : palette.buttonText) - ToolTip.visible: ma.hovered - ToolTip.text: { - if (isAdmin) - return qsTr("Administrator: %1").arg(model.powerlevel); - else if (isModerator) - return qsTr("Moderator: %1").arg(model.powerlevel); - else - return qsTr("User: %1").arg(model.powerlevel); - } - - HoverHandler { - id: ma - } - + PowerlevelIndicator { + powerlevel: model.powerlevel + permissions: room.permissions } EncryptionIndicator { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 752aedb0..c09511f6 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -535,6 +535,7 @@ TimelineModel::roleNames() const {IsSender, "isSender"}, {UserId, "userId"}, {UserName, "userName"}, + {UserPowerlevel, "userPowerlevel"}, {Day, "day"}, {Timestamp, "timestamp"}, {Url, "url"}, @@ -597,6 +598,14 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r return QVariant(QString::fromStdString(acc::sender(event))); case UserName: return QVariant(displayName(QString::fromStdString(acc::sender(event)))); + case UserPowerlevel: { + return static_cast(mtx::events::state::PowerLevels{ + cache::client() + ->getStateEvent(room_id_.toStdString()) + .value_or(mtx::events::StateEvent{}) + .content} + .user_level(acc::sender(event))); + } case Day: { QDateTime prevDate = origin_server_ts(event); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index fd1a4396..0901df29 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -241,6 +241,7 @@ public: IsSender, UserId, UserName, + UserPowerlevel, Day, Timestamp, Url, From a6b732caf0e99f4dd832df52eb58832488e33f73 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 10 Aug 2023 10:15:12 +0200 Subject: [PATCH 2/2] Swap PL indicator location --- resources/qml/MessageView.qml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 5768a7a6..a0ff0ff1 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -564,14 +564,25 @@ Item { target: room } + AbstractButton { id: userNameButton + PowerlevelIndicator { + id: powerlevelIndicator + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter + + powerlevel: userPowerlevel + permissions: room ? room.permissions : null + visible: isAdmin || isModerator + } + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: userId ToolTip.visible: hovered + leftPadding: powerlevelIndicator.visible ? 16 : 0 leftInset: 0 - leftPadding: 0 rightInset: 0 rightPadding: 0 @@ -627,13 +638,6 @@ Item { target: Presence } } - - PowerlevelIndicator { - Layout.alignment: Qt.AlignVCenter - powerlevel: userPowerlevel - permissions: room ? room.permissions : null - visible: isAdmin || isModerator - } } } }