Add kick to room member context menu

This commit is contained in:
miruka
2020-04-19 11:12:35 -04:00
parent bdb9a650d9
commit 2a0a3765fc
9 changed files with 71 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ Banner {
avatar.userId: chat.userId
avatar.displayName: chat.userInfo.display_name
avatar.mxc: chat.userInfo.avatar_url
labelText: qsTr("You are not part of this room anymore")
labelText: qsTr("You are no longer part of this room")
buttonModel: [
{

View File

@@ -52,6 +52,23 @@ HTileDelegate {
text: qsTr("Copy user ID")
onTriggered: Clipboard.text = model.id
}
HMenuItemPopupSpawner {
icon.name: "room-kick"
icon.color: theme.colors.negativeBackground
text: model.invited ? qsTr("Disinvite") : qsTr("Kick")
enabled: chat.roomInfo.can_kick
popup: "Popups/KickPopup.qml"
popupParent: chat
properties: ({
userId: chat.userId,
roomId: chat.roomId,
targetUserId: model.id,
targetDisplayName: model.display_name,
targetIsInvited: model.invited,
})
}
}

View File

@@ -0,0 +1,40 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
BoxPopup {
summary.textFormat: Text.StyledText
summary.text:
targetIsInvited ?
qsTr("Withdraw %1's invitation?").arg(coloredTarget) :
qsTr("Kick %1 out of the room?").arg(coloredTarget)
okText: qsTr("Kick")
onOpened: reasonField.field.forceActiveFocus()
onOk: py.callClientCoro(
userId,
"room_kick",
[roomId, targetUserId, reasonField.field.text || null],
)
property string userId
property string roomId
property string targetUserId
property string targetDisplayName
property bool targetIsInvited: false
readonly property string coloredTarget:
utils.coloredNameHtml(targetDisplayName, targetUserId)
HLabeledTextField {
id: reasonField
label.text: qsTr("Optional reason:")
Layout.fillWidth: true
}
}

View File

@@ -160,9 +160,7 @@ QtObject {
}
function coloredNameHtml(
name, userId, displayText=null, disambiguate=false, dim=false,
) {
function coloredNameHtml(name, userId, displayText=null, dim=false) {
// substring: remove leading @
return `<font color="${nameColor(name || userId.substring(1), dim)}">`+
escapeHtml(displayText || name || userId) +
@@ -210,7 +208,7 @@ QtObject {
if (ev.content.includes("%2"))
content = content.arg(coloredNameHtml(
ev.redacter_name, ev.redacter_id, "", false, true,
ev.redacter_name, ev.redacter_id, "", true,
))
return qsTr(