Merge pull request #1535 from Nheko-Reborn/powerlevelsInTimeline

Show an indicator in the timeline for mods and admins
This commit is contained in:
DeepBlueV7.X 2023-08-10 08:19:32 +00:00 committed by GitHub
commit 70ede75aa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 34 deletions

View file

@ -729,6 +729,7 @@ set(QML_SOURCES
resources/qml/components/MainWindowDialog.qml resources/qml/components/MainWindowDialog.qml
resources/qml/components/NhekoTabButton.qml resources/qml/components/NhekoTabButton.qml
resources/qml/components/NotificationBubble.qml resources/qml/components/NotificationBubble.qml
resources/qml/components/PowerlevelIndicator.qml
resources/qml/components/ReorderableListview.qml resources/qml/components/ReorderableListview.qml
resources/qml/components/SpaceMenuLevel.qml resources/qml/components/SpaceMenuLevel.qml
resources/qml/components/TextButton.qml resources/qml/components/TextButton.qml

View file

@ -100,6 +100,7 @@ Item {
required property string url required property string url
required property string userId required property string userId
required property string userName required property string userName
required property int userPowerlevel
ListView.delayRemove: true ListView.delayRemove: true
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
@ -119,6 +120,7 @@ Item {
property date timestamp: wrapper.timestamp property date timestamp: wrapper.timestamp
property string userId: wrapper.userId property string userId: wrapper.userId
property string userName: wrapper.userName property string userName: wrapper.userName
property int userPowerlevel: wrapper.userPowerlevel
active: previousMessageUserId !== userId || previousMessageDay !== day || previousMessageIsStateEvent !== isStateEvent active: previousMessageUserId !== userId || previousMessageDay !== day || previousMessageIsStateEvent !== isStateEvent
//asynchronous: true //asynchronous: true
@ -562,14 +564,25 @@ Item {
target: room target: room
} }
AbstractButton { AbstractButton {
id: userNameButton 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.delay: Nheko.tooltipDelay
ToolTip.text: userId ToolTip.text: userId
ToolTip.visible: hovered ToolTip.visible: hovered
leftPadding: powerlevelIndicator.visible ? 16 : 0
leftInset: 0 leftInset: 0
leftPadding: 0
rightInset: 0 rightInset: 0
rightPadding: 0 rightPadding: 0

View file

@ -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
}
}

View file

@ -4,6 +4,7 @@
import ".." import ".."
import "../ui" import "../ui"
import "../components"
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
@ -159,39 +160,9 @@ ApplicationWindow {
} }
Image { PowerlevelIndicator {
property bool isAdmin: room.permissions.changeLevel(MtxEvent.PowerLevels) <= model.powerlevel powerlevel: model.powerlevel
property bool isModerator: room.permissions.redactLevel() <= model.powerlevel permissions: room.permissions
//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
}
} }
EncryptionIndicator { EncryptionIndicator {

View file

@ -535,6 +535,7 @@ TimelineModel::roleNames() const
{IsSender, "isSender"}, {IsSender, "isSender"},
{UserId, "userId"}, {UserId, "userId"},
{UserName, "userName"}, {UserName, "userName"},
{UserPowerlevel, "userPowerlevel"},
{Day, "day"}, {Day, "day"},
{Timestamp, "timestamp"}, {Timestamp, "timestamp"},
{Url, "url"}, {Url, "url"},
@ -597,6 +598,14 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
return QVariant(QString::fromStdString(acc::sender(event))); return QVariant(QString::fromStdString(acc::sender(event)));
case UserName: case UserName:
return QVariant(displayName(QString::fromStdString(acc::sender(event)))); return QVariant(displayName(QString::fromStdString(acc::sender(event))));
case UserPowerlevel: {
return static_cast<qlonglong>(mtx::events::state::PowerLevels{
cache::client()
->getStateEvent<mtx::events::state::PowerLevels>(room_id_.toStdString())
.value_or(mtx::events::StateEvent<mtx::events::state::PowerLevels>{})
.content}
.user_level(acc::sender(event)));
}
case Day: { case Day: {
QDateTime prevDate = origin_server_ts(event); QDateTime prevDate = origin_server_ts(event);

View file

@ -241,6 +241,7 @@ public:
IsSender, IsSender,
UserId, UserId,
UserName, UserName,
UserPowerlevel,
Day, Day,
Timestamp, Timestamp,
Url, Url,