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 "./delegates"
import "./emoji" import "./emoji"
import "./ui" import "./ui"
import "./dialogs"
import Qt.labs.platform 1.1 as Platform import Qt.labs.platform 1.1 as Platform
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
@ -585,6 +586,21 @@ Item {
open(); 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 { Platform.MenuItem {
visible: messageContextMenu.text visible: messageContextMenu.text
enabled: visible enabled: visible
@ -665,7 +681,13 @@ Item {
Platform.MenuItem { Platform.MenuItem {
visible: (room ? room.permissions.canRedact() : false) || messageContextMenu.isSender visible: (room ? room.permissions.canRedact() : false) || messageContextMenu.isSender
text: qsTr("Remo&ve message") 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 { Platform.MenuItem {

View File

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

View File

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

View File

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

View File

@ -272,7 +272,7 @@ public:
Q_INVOKABLE void unpin(const QString &id); Q_INVOKABLE void unpin(const QString &id);
Q_INVOKABLE void pin(const QString &id); Q_INVOKABLE void pin(const QString &id);
Q_INVOKABLE void showReadReceipts(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 int idToIndex(const QString &id) const;
Q_INVOKABLE QString indexToId(int index) const; Q_INVOKABLE QString indexToId(int index) const;
Q_INVOKABLE void openMedia(const QString &eventId); Q_INVOKABLE void openMedia(const QString &eventId);