From b3f107550761249352559229cbf9772d0f320865 Mon Sep 17 00:00:00 2001 From: vSLG Date: Thu, 26 Mar 2020 17:31:57 -0300 Subject: [PATCH] Add redacting event via context menu --- src/backend/matrix_client.py | 12 +++++++ src/gui/Pages/Chat/Timeline/EventDelegate.qml | 13 ++++++++ src/gui/Popups/RedactEvents.qml | 32 +++++++++++++++++++ src/icons/thin/remove-message.svg | 1 + 4 files changed, 58 insertions(+) create mode 100644 src/gui/Popups/RedactEvents.qml create mode 100644 src/icons/thin/remove-message.svg diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 1f2ec118..1875b50a 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -875,6 +875,18 @@ class MatrixClient(nio.AsyncClient): return (successes, errors) + async def room_mass_redact( + self, room_id: str, reason: str, *event_ids: str, + ): + """Redact events from a room in parallel. + + Returns a list of sucessful redacts. + """ + + return await asyncio.gather(*[ + self.room_redact(room_id, evt_id, reason) + for evt_id in event_ids + ]) async def generate_thumbnail( self, data: UploadData, is_svg: bool = False, diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index fdbc562c..780f5671 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -218,6 +218,19 @@ HColumnLayout { } } + HMenuItemPopupSpawner { + icon.name: "remove-message" + text: qsTr("Remove") + + popup: "Popups/RedactEvents.qml" + popupParent: chat + properties: ({ + userId: chat.userId, + roomId: chat.roomId, + eventIds: [model.event_id] + }) + } + HMenuItem { icon.name: "debug" text: qsTr("Debug this event") diff --git a/src/gui/Popups/RedactEvents.qml b/src/gui/Popups/RedactEvents.qml new file mode 100644 index 00000000..bcb54c47 --- /dev/null +++ b/src/gui/Popups/RedactEvents.qml @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Layouts 1.12 +import "../Base" + +BoxPopup { + summary.text: + eventIds.length > 1 ? + qsTr("Remove selected messages?") : + qsTr("Remove selected message?") + + HLabeledTextField { + id: reasonField + label.text: qsTr("Reason (optional):") + Layout.fillWidth: true + } + + okText: qsTr("Remove") + box.focusButton: "ok" + + onOk: py.callClientCoro( + userId, + "room_mass_redact", + [roomId, reasonField.field.text, ...eventIds] + ) + + property string roomId: "" + property string userId: "" + + property var eventIds: [] +} diff --git a/src/icons/thin/remove-message.svg b/src/icons/thin/remove-message.svg new file mode 100644 index 00000000..e6e3bfcf --- /dev/null +++ b/src/icons/thin/remove-message.svg @@ -0,0 +1 @@ + \ No newline at end of file