From 93909c45eebd880ad1defd01094fa536a36a8133 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 2 Sep 2024 14:37:14 +0200 Subject: [PATCH] Refactor dialogs for reporting, banning, and removing messages --- src/CMakeLists.txt | 4 +- src/qml/DelegateContextMenu.qml | 44 +++++++++------ src/qml/FileDelegateContextMenu.qml | 21 +++++--- src/qml/{BanSheet.qml => ReasonDialog.qml} | 17 +++--- src/qml/RemoveSheet.qml | 63 ---------------------- src/qml/ReportSheet.qml | 58 -------------------- src/qml/UserDetailDialog.qml | 26 ++++++--- 7 files changed, 71 insertions(+), 162 deletions(-) rename src/qml/{BanSheet.qml => ReasonDialog.qml} (73%) delete mode 100644 src/qml/RemoveSheet.qml delete mode 100644 src/qml/ReportSheet.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bbe2c1a83..967369501 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -243,10 +243,7 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE qml/MessageDelegateContextMenu.qml qml/FileDelegateContextMenu.qml qml/MessageSourceSheet.qml - qml/ReportSheet.qml qml/ConfirmEncryptionDialog.qml - qml/RemoveSheet.qml - qml/BanSheet.qml qml/RoomSearchPage.qml qml/LocationChooser.qml qml/TimelineView.qml @@ -291,6 +288,7 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE qml/AskDirectChatConfirmation.qml qml/HoverLinkIndicator.qml qml/AvatarNotification.qml + qml/ReasonDialog.qml DEPENDENCIES QtCore QtQuick diff --git a/src/qml/DelegateContextMenu.qml b/src/qml/DelegateContextMenu.qml index 4ef2ab1bb..953365c8a 100644 --- a/src/qml/DelegateContextMenu.qml +++ b/src/qml/DelegateContextMenu.qml @@ -82,16 +82,23 @@ Loader { component RemoveMessageAction: Kirigami.Action { visible: author.isLocalMember || currentRoom.canSendState("redact") - text: i18n("Remove") + text: i18nc("@action:button", "Remove") icon.name: "edit-delete-remove" icon.color: "red" - onTriggered: applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RemoveSheet'), { - room: currentRoom, - eventId: eventId - }, { - title: i18nc("@title", "Remove Message"), - width: Kirigami.Units.gridUnit * 25 - }) + onTriggered: { + let dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), { + title: i18nc("@title:dialog", "Remove Message"), + placeholder: i18nc("@info:placeholder", "Reason for removing this message"), + actionText: i18nc("@action:button 'Remove' as in 'Remove this message'", "Remove"), + icon: "delete" + }, { + title: i18nc("@title:dialog", "Remove Message"), + width: Kirigami.Units.gridUnit * 25 + }); + dialog.accepted.connect(reason => { + currentRoom.redactEvent(root.eventId, reason); + }); + } } component ReplyMessageAction: Kirigami.Action { @@ -108,13 +115,20 @@ Loader { text: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report") icon.name: "dialog-warning-symbolic" visible: !author.isLocalMember - onTriggered: applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReportSheet'), { - room: currentRoom, - eventId: eventId - }, { - title: i18nc("@title", "Report Message"), - width: Kirigami.Units.gridUnit * 25 - }) + onTriggered: { + let dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), { + title: i18nc("@title:dialog", "Report Message"), + placeholder: i18nc("@info:placeholder", "Reason for reporting this message"), + icon: "dialog-warning-symbolic", + actionText: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report") + }, { + title: i18nc("@title", "Report Message"), + width: Kirigami.Units.gridUnit * 25 + }); + dialog.accepted.connect(reason => { + currentRoom.reportEvent(root.eventId, reason); + }); + } } Component { diff --git a/src/qml/FileDelegateContextMenu.qml b/src/qml/FileDelegateContextMenu.qml index 88a919211..3f4bb00dd 100644 --- a/src/qml/FileDelegateContextMenu.qml +++ b/src/qml/FileDelegateContextMenu.qml @@ -67,13 +67,20 @@ DelegateContextMenu { text: i18n("Remove") icon.name: "edit-delete-remove" icon.color: "red" - onTriggered: applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RemoveSheet'), { - room: currentRoom, - eventId: eventId - }, { - title: i18nc("@title", "Remove Message"), - width: Kirigami.Units.gridUnit * 25 - }) + onTriggered: { + let dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), { + title: i18nc("@title:dialog", "Remove Message"), + placeholder: i18nc("@info:placeholder", "Reason for removing this message"), + actionText: i18nc("@action:button 'Remove' as in 'Remove this message'", "Remove"), + icon: "delete" + }, { + title: i18nc("@title:dialog", "Remove Message"), + width: Kirigami.Units.gridUnit * 25 + }); + dialog.accepted.connect(reason => { + currentRoom.redactEvent(root.eventId, reason); + }); + } }, DelegateContextMenu.ReportMessageAction {}, DelegateContextMenu.ViewSourceAction {} diff --git a/src/qml/BanSheet.qml b/src/qml/ReasonDialog.qml similarity index 73% rename from src/qml/BanSheet.qml rename to src/qml/ReasonDialog.qml index 2e7cab21b..7c346cbef 100644 --- a/src/qml/BanSheet.qml +++ b/src/qml/ReasonDialog.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 Tobias Fella +// SPDX-FileCopyrightText: 2024 Tobias Fella // SPDX-License-Identifier: GPL-2.0-or-later import QtQuick @@ -12,10 +12,11 @@ import org.kde.neochat Kirigami.Page { id: root - property NeoChatRoom room - property string userId + required property string placeholder + required property string actionText + required property string icon - title: i18n("Ban User") + signal accepted(reason: string) leftPadding: 0 rightPadding: 0 @@ -24,7 +25,7 @@ Kirigami.Page { QQC2.TextArea { id: reason - placeholderText: i18n("Reason for banning this user") + placeholderText: root.placeholder anchors.fill: parent wrapMode: TextEdit.Wrap @@ -40,11 +41,11 @@ Kirigami.Page { Layout.fillWidth: true } QQC2.Button { - text: i18nc("@action:button 'Ban' as in 'Ban this user'", "Ban") - icon.name: "im-ban-user" + text: root.actionText + icon.name: root.icon QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole onClicked: { - root.room.ban(root.userId, reason.text); + root.accepted(reason.text); root.closeDialog(); } } diff --git a/src/qml/RemoveSheet.qml b/src/qml/RemoveSheet.qml deleted file mode 100644 index e2dcef296..000000000 --- a/src/qml/RemoveSheet.qml +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Tobias Fella -// SPDX-License-Identifier: GPL-2.0-or-later - -import QtQuick -import QtQuick.Controls as QQC2 -import QtQuick.Layouts - -import org.kde.kirigami as Kirigami - -import org.kde.neochat - -Kirigami.Page { - id: root - - property NeoChatRoom room - property string eventId - - property string userId: "" - - title: userId.length > 0 ? i18n("Remove Messages") : i18n("Remove Message") - - leftPadding: 0 - rightPadding: 0 - topPadding: 0 - bottomPadding: 0 - - QQC2.TextArea { - id: reason - placeholderText: userId.length > 0 ? i18n("Reason for removing this user's recent messages") : i18n("Reason for removing this message") - anchors.fill: parent - wrapMode: TextEdit.Wrap - background: Rectangle { - color: Kirigami.Theme.backgroundColor - } - } - - footer: QQC2.ToolBar { - QQC2.DialogButtonBox { - anchors.fill: parent - Item { - Layout.fillWidth: true - } - QQC2.Button { - text: i18nc("@action:button 'Remove' as in 'Remove this message'", "Remove") - icon.name: "delete" - QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole - onClicked: { - if (root.userId.length > 0) { - root.room.deleteMessagesByUser(root.userId, reason.text); - } else { - root.room.redactEvent(root.eventId, reason.text); - } - root.closeDialog(); - } - } - QQC2.Button { - text: i18nc("@action", "Cancel") - QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole - onClicked: root.closeDialog() - } - } - } -} diff --git a/src/qml/ReportSheet.qml b/src/qml/ReportSheet.qml deleted file mode 100644 index ff69100c0..000000000 --- a/src/qml/ReportSheet.qml +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Tobias Fella -// SPDX-License-Identifier: GPL-2.0-or-later - -import QtQuick -import QtQuick.Controls as QQC2 -import QtQuick.Layouts - -import org.kde.kirigami as Kirigami - -import org.kde.neochat - -Kirigami.Page { - id: root - - property NeoChatRoom room - property string eventId - - title: i18n("Report Message") - - leftPadding: 0 - rightPadding: 0 - topPadding: 0 - bottomPadding: 0 - - QQC2.TextArea { - id: reason - placeholderText: i18n("Reason for reporting this message") - anchors.fill: parent - wrapMode: TextEdit.Wrap - - background: Rectangle { - color: Kirigami.Theme.backgroundColor - } - } - - footer: QQC2.ToolBar { - QQC2.DialogButtonBox { - anchors.fill: parent - Item { - Layout.fillWidth: true - } - QQC2.Button { - text: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report") - icon.name: "dialog-warning-symbolic" - QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole - onClicked: { - root.room.reportEvent(eventId, reason.text); - root.closeDialog(); - } - } - QQC2.Button { - text: i18nc("@action", "Cancel") - QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole - onClicked: root.closeDialog() - } - } - } -} diff --git a/src/qml/UserDetailDialog.qml b/src/qml/UserDetailDialog.qml index 7b60ccf8f..d5263f9b9 100644 --- a/src/qml/UserDetailDialog.qml +++ b/src/qml/UserDetailDialog.qml @@ -150,13 +150,18 @@ Kirigami.Dialog { icon.name: "im-ban-user" icon.color: Kirigami.Theme.negativeTextColor onTriggered: { - (root.QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow).pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'BanSheet'), { - room: root.room, - userId: root.user.id + let dialog = (root.QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow).pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), { + title: i18nc("@title:dialog", "Ban User"), + placeholder: i18nc("@info:placeholder", "Reason for banning this user"), + actionText: i18nc("@action:button 'Ban' as in 'Ban this user'", "Ban"), + icon: "im-ban-user" }, { - title: i18nc("@title", "Ban User"), + title: i18nc("@title:dialog", "Ban User"), width: Kirigami.Units.gridUnit * 25 }); + dialog.accepted.connect(reason => { + root.room.ban(root.user.id, reason); + }); root.close(); } } @@ -204,17 +209,22 @@ Kirigami.Dialog { visible: root.room && (root.user.id === root.connection.localUserId || room.canSendState("redact")) action: Kirigami.Action { - text: i18n("Remove recent messages by this user") + text: i18nc("@action:button", "Remove recent messages by this user") icon.name: "delete" icon.color: Kirigami.Theme.negativeTextColor onTriggered: { - applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RemoveSheet'), { - room: root.room, - userId: root.user.id + let dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), { + title: i18nc("@title:dialog", "Remove Messages"), + placeholder: i18nc("@info:placeholder", "Reason for removing this user's recent messages"), + actionText: i18nc("@action:button 'Remove' as in 'Remove these messages'", "Remove"), + icon: "delete" }, { title: i18nc("@title", "Remove Messages"), width: Kirigami.Units.gridUnit * 25 }); + dialog.accepted.connect(reason => { + root.room.deleteMessagesByUser(root.user.id, reason); + }); root.close(); } }