From 29584aec23bac3e2fde58567b672519124275b20 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 5 Dec 2020 11:29:37 +0100 Subject: [PATCH] Allow redaction of message only by admins and authors of the message Previously you could click on the button but it would do nothing --- imports/NeoChat/Component/Timeline/AudioDelegate.qml | 3 ++- imports/NeoChat/Component/Timeline/FileDelegate.qml | 2 +- imports/NeoChat/Component/Timeline/ImageDelegate.qml | 2 +- imports/NeoChat/Component/Timeline/VideoDelegate.qml | 2 +- .../NeoChat/Menu/Timeline/FileDelegateContextMenu.qml | 9 ++++++--- .../NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml | 1 + 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/imports/NeoChat/Component/Timeline/AudioDelegate.qml b/imports/NeoChat/Component/Timeline/AudioDelegate.qml index 95eda5be5..9daff9091 100644 --- a/imports/NeoChat/Component/Timeline/AudioDelegate.qml +++ b/imports/NeoChat/Component/Timeline/AudioDelegate.qml @@ -21,6 +21,7 @@ import NeoChat.Effect 1.0 Control { id: root + Layout.fillWidth: true Audio { @@ -32,7 +33,7 @@ Control { Kirigami.Action { id: saveFileAction onTriggered: { - let contextMenu = fileDelegateContextMenu.createObject(root) + let contextMenu = fileDelegateContextMenu.createObject(root, {'room': currentRoom, 'author': author}); contextMenu.viewSource.connect(function() { messagerSourceSheet.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() }) diff --git a/imports/NeoChat/Component/Timeline/FileDelegate.qml b/imports/NeoChat/Component/Timeline/FileDelegate.qml index f3a9e9790..ed5e831a0 100644 --- a/imports/NeoChat/Component/Timeline/FileDelegate.qml +++ b/imports/NeoChat/Component/Timeline/FileDelegate.qml @@ -61,7 +61,7 @@ RowLayout { anchors.fill: parent acceptedButtons: Qt.RightButton onClicked: { - var contextMenu = fileDelegateContextMenu.createObject(root) + var contextMenu = fileDelegateContextMenu.createObject(root, {'room': currentRoom, 'author': author}); contextMenu.viewSource.connect(function() { messageSourceSheet.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() }) diff --git a/imports/NeoChat/Component/Timeline/ImageDelegate.qml b/imports/NeoChat/Component/Timeline/ImageDelegate.qml index c903bd3b3..9daf36f04 100644 --- a/imports/NeoChat/Component/Timeline/ImageDelegate.qml +++ b/imports/NeoChat/Component/Timeline/ImageDelegate.qml @@ -93,7 +93,7 @@ Image { onPrimaryClicked: fullScreenImage.createObject(parent, {"filename": eventId, "localPath": currentRoom.urlToDownload(eventId)}).showFullScreen() onSecondaryClicked: { - var contextMenu = imageDelegateContextMenu.createObject(root) + var contextMenu = imageDelegateContextMenu.createObject(root, {'room': currentRoom}); contextMenu.viewSource.connect(function() { messageSourceSheet.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() }) diff --git a/imports/NeoChat/Component/Timeline/VideoDelegate.qml b/imports/NeoChat/Component/Timeline/VideoDelegate.qml index e942966bf..e376dbd4d 100644 --- a/imports/NeoChat/Component/Timeline/VideoDelegate.qml +++ b/imports/NeoChat/Component/Timeline/VideoDelegate.qml @@ -172,7 +172,7 @@ Video { } onSecondaryClicked: { - var contextMenu = imageDelegateContextMenu.createObject(vid) + var contextMenu = imageDelegateContextMenu.createObject(vid, {'room': currentRoom, 'author': author}) contextMenu.viewSource.connect(function() { messageSourceSheet.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() }) diff --git a/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml b/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml index bf4ad03e2..f3e3f79e2 100644 --- a/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml +++ b/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml @@ -9,14 +9,17 @@ import QtQuick.Controls 2.12 import NeoChat.Dialog 1.0 Menu { + id: root + + required property var room + required property var author + signal viewSource() signal downloadAndOpen() signal saveFileAs() signal reply() signal redact() - id: root - MenuItem { text: i18n("View Source") @@ -42,8 +45,8 @@ Menu { } MenuItem { + visible: room.canSendState("redact") || room.localUser.id === author.id text: i18n("Redact") - onTriggered: redact() } diff --git a/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml b/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml index e023641c6..740bf3817 100644 --- a/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml +++ b/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml @@ -91,6 +91,7 @@ Kirigami.OverlaySheet { } } Kirigami.BasicListItem { + visible: author.id === currentRoom.localUser.id || currentRoom.canSendState("redact") action: Kirigami.Action { text: i18n("Remove") icon.name: "edit-delete-remove"