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:
James Graham
2023-03-05 22:44:04 +00:00
committed by Tobias Fella
parent e6a060c192
commit bd4eeb405b
6 changed files with 115 additions and 37 deletions

View 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()
}
}
}
}

View File

@@ -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 {
visible: user === room.localUser || room.canSendState("redact")