Set power level from userdetaildialog
Add the option to set powerlevel to userdetaildialog. This is done by making the powerleveldialog into it's own file and using that. implements network/neochat#570
This commit is contained in:
committed by
Tobias Fella
parent
e6a060c192
commit
bd4eeb405b
@@ -1075,6 +1075,12 @@ void NeoChatRoom::setHistoryVisibility(const QString &historyVisibilityRule)
|
|||||||
// Not emitting historyVisibilityChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value.
|
// Not emitting historyVisibilityChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NeoChatRoom::getUserPowerLevel(const QString &userId) const
|
||||||
|
{
|
||||||
|
auto powerLevelEvent = getCurrentState<RoomPowerLevelsEvent>();
|
||||||
|
return powerLevelEvent->powerLevelForUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
void NeoChatRoom::setUserPowerLevel(const QString &userID, const int &powerLevel)
|
void NeoChatRoom::setUserPowerLevel(const QString &userID, const int &powerLevel)
|
||||||
{
|
{
|
||||||
if (joinedCount() <= 1) {
|
if (joinedCount() <= 1) {
|
||||||
|
|||||||
@@ -153,6 +153,14 @@ public:
|
|||||||
[[nodiscard]] QString historyVisibility() const;
|
[[nodiscard]] QString historyVisibility() const;
|
||||||
void setHistoryVisibility(const QString &historyVisibilityRule);
|
void setHistoryVisibility(const QString &historyVisibilityRule);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the power level for the given user ID in the room.
|
||||||
|
*
|
||||||
|
* Returns the default value for a user in the room if they have no escalated
|
||||||
|
* privileges or if they are not a member so membership should be known before using.
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE [[nodiscard]] int getUserPowerLevel(const QString &userId) const;
|
||||||
|
|
||||||
Q_INVOKABLE void setUserPowerLevel(const QString &userID, const int &powerLevel);
|
Q_INVOKABLE void setUserPowerLevel(const QString &userID, const int &powerLevel);
|
||||||
|
|
||||||
[[nodiscard]] int powerLevel(const QString &eventName, const bool &isStateEvent = false) const;
|
[[nodiscard]] int powerLevel(const QString &eventName, const bool &isStateEvent = false) const;
|
||||||
|
|||||||
51
src/qml/Dialog/PowerLevelDialog.qml
Normal file
51
src/qml/Dialog/PowerLevelDialog.qml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||||
|
|
||||||
|
import QtQuick 2.15
|
||||||
|
import QtQuick.Controls 2.15 as QQC2
|
||||||
|
import QtQuick.Layouts 1.15
|
||||||
|
|
||||||
|
import org.kde.kirigami 2.15 as Kirigami
|
||||||
|
|
||||||
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
|
Kirigami.OverlaySheet {
|
||||||
|
id: root
|
||||||
|
title: i18n("Edit user power level")
|
||||||
|
|
||||||
|
property var room
|
||||||
|
property var userId
|
||||||
|
property int powerLevel
|
||||||
|
|
||||||
|
onSheetOpenChanged: {
|
||||||
|
if (sheetOpen) {
|
||||||
|
powerLevelComboBox.currentIndex = powerLevelComboBox.indexOfValue(root.powerLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Kirigami.FormLayout {
|
||||||
|
QQC2.ComboBox {
|
||||||
|
id: powerLevelComboBox
|
||||||
|
model: ListModel {
|
||||||
|
id: powerLevelModel
|
||||||
|
}
|
||||||
|
textRole: "text"
|
||||||
|
valueRole: "powerLevel"
|
||||||
|
popup.z: root.z + 1 // Otherwise the popup will be behind the overlay sheet.
|
||||||
|
|
||||||
|
// Done this way so we can have translated strings.
|
||||||
|
Component.onCompleted: {
|
||||||
|
powerLevelModel.append({"text": i18n("Member (0)"), "powerLevel": 0});
|
||||||
|
powerLevelModel.append({"text": i18n("Moderator (50)"), "powerLevel": 50});
|
||||||
|
powerLevelModel.append({"text": i18n("Admin (100)"), "powerLevel": 100});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QQC2.Button {
|
||||||
|
text: i18n("Confirm")
|
||||||
|
onClicked: {
|
||||||
|
room.setUserPowerLevel(root.userId, powerLevelComboBox.currentValue)
|
||||||
|
root.close()
|
||||||
|
root.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,6 +139,29 @@ Kirigami.OverlaySheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Kirigami.BasicListItem {
|
||||||
|
visible: room.canSendState("m.room.power_levels")
|
||||||
|
action: Kirigami.Action {
|
||||||
|
text: i18n("Set user power level")
|
||||||
|
icon.name: "visibility"
|
||||||
|
onTriggered: {
|
||||||
|
let dialog = powerLevelDialog.createObject(applicationWindow().overlay, {
|
||||||
|
room: root.room,
|
||||||
|
userId: root.user.id,
|
||||||
|
powerLevel: root.room.getUserPowerLevel(root.user.id)
|
||||||
|
});
|
||||||
|
dialog.open()
|
||||||
|
root.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: powerLevelDialog
|
||||||
|
PowerLevelDialog {
|
||||||
|
id: powerLevelDialog
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Kirigami.BasicListItem {
|
Kirigami.BasicListItem {
|
||||||
visible: user === room.localUser || room.canSendState("redact")
|
visible: user === room.localUser || room.canSendState("redact")
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ Kirigami.ScrollablePage {
|
|||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: powerLevelModel
|
id: powerLevelModel
|
||||||
ListElement {text: "Member (0)"; powerLevel: 0}
|
|
||||||
ListElement {text: "Moderator (50)"; powerLevel: 50}
|
|
||||||
ListElement {text: "Admin (100)"; powerLevel: 100}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@@ -67,7 +64,19 @@ Kirigami.ScrollablePage {
|
|||||||
textRole: "text"
|
textRole: "text"
|
||||||
valueRole: "powerLevel"
|
valueRole: "powerLevel"
|
||||||
visible: room.canSendState("m.room.power_levels")
|
visible: room.canSendState("m.room.power_levels")
|
||||||
Component.onCompleted: currentIndex = indexOfValue(powerLevel)
|
Component.onCompleted: {
|
||||||
|
/**
|
||||||
|
* This is very silly but the only way to populate the model with
|
||||||
|
* translated strings. Done here because the model needs to be filled
|
||||||
|
* before the first delegate sets it's current index.
|
||||||
|
*/
|
||||||
|
if (powerLevelModel.count == 0) {
|
||||||
|
powerLevelModel.append({"text": i18n("Member (0)"), "powerLevel": 0});
|
||||||
|
powerLevelModel.append({"text": i18n("Moderator (50)"), "powerLevel": 50});
|
||||||
|
powerLevelModel.append({"text": i18n("Admin (100)"), "powerLevel": 100});
|
||||||
|
}
|
||||||
|
currentIndex = indexOfValue(powerLevel)
|
||||||
|
}
|
||||||
onActivated: {
|
onActivated: {
|
||||||
room.setUserPowerLevel(userId, currentValue)
|
room.setUserPowerLevel(userId, currentValue)
|
||||||
}
|
}
|
||||||
@@ -162,9 +171,12 @@ Kirigami.ScrollablePage {
|
|||||||
id: editPowerLevelAction
|
id: editPowerLevelAction
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
userListSearchPopup.close()
|
userListSearchPopup.close()
|
||||||
powerLevelSheet.userId = userId
|
let dialog = powerLevelDialog.createObject(applicationWindow().overlay, {
|
||||||
powerLevelSheet.powerLevel = powerLevel
|
room: root.room,
|
||||||
powerLevelSheet.open()
|
userId: model.userId,
|
||||||
|
powerLevel: model.powerLevel
|
||||||
|
});
|
||||||
|
dialog.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +196,13 @@ Kirigami.ScrollablePage {
|
|||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
wrapMode: Text.NoWrap
|
wrapMode: Text.NoWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: powerLevelDialog
|
||||||
|
PowerLevelDialog {
|
||||||
|
id: powerLevelDialog
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,34 +412,4 @@ Kirigami.ScrollablePage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Kirigami.OverlaySheet {
|
|
||||||
id: powerLevelSheet
|
|
||||||
title: i18n("Edit user power level")
|
|
||||||
|
|
||||||
property var userId
|
|
||||||
property int powerLevel
|
|
||||||
|
|
||||||
onSheetOpenChanged: {
|
|
||||||
if (sheetOpen) {
|
|
||||||
powerLevelComboBox.currentIndex = powerLevelComboBox.indexOfValue(powerLevelSheet.powerLevel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Kirigami.FormLayout {
|
|
||||||
QQC2.ComboBox {
|
|
||||||
id: powerLevelComboBox
|
|
||||||
focusPolicy: Qt.NoFocus // provided by parent
|
|
||||||
model: powerLevelModel
|
|
||||||
textRole: "text"
|
|
||||||
valueRole: "powerLevel"
|
|
||||||
visible: room.canSendState("m.room.power_levels")
|
|
||||||
}
|
|
||||||
QQC2.Button {
|
|
||||||
text: i18n("Confirm")
|
|
||||||
onClicked: {
|
|
||||||
room.setUserPowerLevel(powerLevelSheet.userId, powerLevelComboBox.currentValue)
|
|
||||||
powerLevelSheet.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
<file alias="OpenFileDialog.qml">qml/Dialog/OpenFileDialog.qml</file>
|
<file alias="OpenFileDialog.qml">qml/Dialog/OpenFileDialog.qml</file>
|
||||||
<file alias="KeyVerificationDialog.qml">qml/Dialog/KeyVerification/KeyVerificationDialog.qml</file>
|
<file alias="KeyVerificationDialog.qml">qml/Dialog/KeyVerification/KeyVerificationDialog.qml</file>
|
||||||
<file alias="ConfirmLogoutDialog.qml">qml/Dialog/ConfirmLogoutDialog.qml</file>
|
<file alias="ConfirmLogoutDialog.qml">qml/Dialog/ConfirmLogoutDialog.qml</file>
|
||||||
|
<file alias="PowerLevelDialog.qml">qml/Dialog/PowerLevelDialog.qml</file>
|
||||||
<file alias="Message.qml">qml/Dialog/KeyVerification/Message.qml</file>
|
<file alias="Message.qml">qml/Dialog/KeyVerification/Message.qml</file>
|
||||||
<file alias="EmojiItem.qml">qml/Dialog/KeyVerification/EmojiItem.qml</file>
|
<file alias="EmojiItem.qml">qml/Dialog/KeyVerification/EmojiItem.qml</file>
|
||||||
<file alias="EmojiRow.qml">qml/Dialog/KeyVerification/EmojiRow.qml</file>
|
<file alias="EmojiRow.qml">qml/Dialog/KeyVerification/EmojiRow.qml</file>
|
||||||
|
|||||||
Reference in New Issue
Block a user