Merge pull request #976 from tastytea/redaction-reason

Add GUI for redact/kick/ban reasons
This commit is contained in:
DeepBlueV7.X 2022-03-06 23:39:27 +00:00 committed by GitHub
commit 54d93becbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import "./components"
import "./delegates"
import "./emoji"
import "./ui"
import "./dialogs"
import Qt.labs.platform 1.1 as Platform
import QtQuick 2.15
import QtQuick.Controls 2.15
@ -585,6 +586,21 @@ Item {
open();
}
Component {
id: removeReason
InputDialog {
id: removeReasonDialog
property string eventId
title: qsTr("Reason for removal")
prompt: qsTr("Enter reason for removal or hit enter for no reason:")
onAccepted: function(text) {
room.redactEvent(eventId, text);
}
}
}
Platform.MenuItem {
visible: messageContextMenu.text
enabled: visible
@ -665,7 +681,13 @@ Item {
Platform.MenuItem {
visible: (room ? room.permissions.canRedact() : false) || messageContextMenu.isSender
text: qsTr("Remo&ve message")
onTriggered: room.redactEvent(messageContextMenu.eventId)
onTriggered: function() {
var dialog = removeReason.createObject(timelineRoot);
dialog.eventId = messageContextMenu.eventId;
dialog.show();
dialog.forceActiveFocus();
timelineRoot.destroyOnClose(dialog);
}
}
Platform.MenuItem {

View File

@ -21,6 +21,10 @@ ApplicationWindow {
width: 350
height: fontMetrics.lineSpacing * 7
function forceActiveFocus() {
statusInput.forceActiveFocus();
}
Shortcut {
sequence: StandardKey.Cancel
onActivated: dbb.rejected()

View File

@ -785,11 +785,18 @@ ChatPage::kickUser(QString userid, QString reason)
{
auto room = currentRoom();
if (QMessageBox::question(nullptr,
tr("Confirm kick"),
tr("Do you really want to kick %1 (%2)?")
.arg(cache::displayName(room, userid), userid)) != QMessageBox::Yes)
bool confirmed;
reason =
QInputDialog::getText(nullptr,
tr("Reason for the kick"),
tr("Enter reason for kicking %1 (%2) or hit enter for no reason:")
.arg(cache::displayName(room, userid), userid),
QLineEdit::Normal,
reason,
&confirmed);
if (!confirmed) {
return;
}
http::client()->kick_user(
room.toStdString(),
@ -809,12 +816,18 @@ ChatPage::banUser(QString userid, QString reason)
{
auto room = currentRoom();
if (QMessageBox::question(
nullptr,
tr("Confirm ban"),
tr("Do you really want to ban %1 (%2)?").arg(cache::displayName(room, userid), userid)) !=
QMessageBox::Yes)
bool confirmed;
reason =
QInputDialog::getText(nullptr,
tr("Reason for the ban"),
tr("Enter reason for banning %1 (%2) or hit enter for no reason:")
.arg(cache::displayName(room, userid), userid),
QLineEdit::Normal,
reason,
&confirmed);
if (!confirmed) {
return;
}
http::client()->ban_user(
room.toStdString(),

View File

@ -1240,7 +1240,7 @@ TimelineModel::showReadReceipts(QString id)
}
void
TimelineModel::redactEvent(const QString &id)
TimelineModel::redactEvent(const QString &id, const QString &reason)
{
if (!id.isEmpty()) {
auto edits = events.edits(id.toStdString());
@ -1255,7 +1255,8 @@ TimelineModel::redactEvent(const QString &id)
}
emit dataAtIdChanged(id);
});
},
reason.toStdString());
// redact all edits to prevent leaks
for (const auto &e : edits) {
@ -1271,7 +1272,8 @@ TimelineModel::redactEvent(const QString &id)
}
emit dataAtIdChanged(id);
});
},
reason.toStdString());
}
}
}

View File

@ -272,7 +272,7 @@ public:
Q_INVOKABLE void unpin(const QString &id);
Q_INVOKABLE void pin(const QString &id);
Q_INVOKABLE void showReadReceipts(QString id);
Q_INVOKABLE void redactEvent(const QString &id);
Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = "");
Q_INVOKABLE int idToIndex(const QString &id) const;
Q_INVOKABLE QString indexToId(int index) const;
Q_INVOKABLE void openMedia(const QString &eventId);