diff --git a/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml b/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml index ed57d8cf2..27d50c786 100644 --- a/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml +++ b/imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml @@ -66,6 +66,15 @@ MessageDelegateContextMenu { root.closeFullscreen() } }, + Kirigami.Action { + text: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report") + icon.name: "dialog-warning-symbolic" + visible: author.id !== currentRoom.localUser.id + onTriggered: applicationWindow().pageStack.pushDialogLayer("qrc:/imports/NeoChat/Menu/Timeline/ReportSheet.qml", {room: currentRoom, eventId: eventId}, { + title: i18nc("@title", "Report Message"), + width: Kirigami.Units.gridUnit * 25 + }) + }, Kirigami.Action { text: i18n("View Source") icon.name: "code-context" diff --git a/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml b/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml index 1ade0ae65..0fbfd60f7 100644 --- a/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml +++ b/imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml @@ -48,6 +48,15 @@ Loader { icon.name: "edit-copy" onTriggered: Clipboard.saveText(loadRoot.selectedText === "" ? loadRoot.plainMessage : loadRoot.selectedText) }, + Kirigami.Action { + text: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report") + icon.name: "dialog-warning-symbolic" + visible: author.id !== currentRoom.localUser.id + onTriggered: applicationWindow().pageStack.pushDialogLayer("qrc:/imports/NeoChat/Menu/Timeline/ReportSheet.qml", {room: currentRoom, eventId: eventId}, { + title: i18nc("@title", "Report Message"), + width: Kirigami.Units.gridUnit * 25 + }) + }, Kirigami.Action { text: i18n("View Source") icon.name: "code-context" diff --git a/imports/NeoChat/Menu/Timeline/ReportSheet.qml b/imports/NeoChat/Menu/Timeline/ReportSheet.qml new file mode 100644 index 000000000..f11d99a6e --- /dev/null +++ b/imports/NeoChat/Menu/Timeline/ReportSheet.qml @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2022 Tobias Fella +// SPDX-License-Identifier: GPL-2.0-or-later + +import QtQuick 2.15 +import QtQuick.Controls 2.15 as QQC2 +import QtQuick.Layouts 1.15 + +import org.kde.kirigami 2.20 as Kirigami + +Kirigami.Page { + id: reportSheet + + property var room + property string eventId + + title: i18n("Report Message") + + QQC2.TextArea { + id: reason + placeholderText: i18n("Reason for reporting this message") + anchors.fill: parent + wrapMode: TextEdit.Wrap + } + + 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: { + reportSheet.room.reportEvent(eventId, reason.text) + reportSheet.closeDialog() + } + } + QQC2.Button { + text: i18nc("@action", "Cancel") + QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole + onClicked: reportSheet.closeDialog() + } + } + } +} diff --git a/imports/NeoChat/Menu/Timeline/qmldir b/imports/NeoChat/Menu/Timeline/qmldir index 3400daef4..2a9245e4e 100644 --- a/imports/NeoChat/Menu/Timeline/qmldir +++ b/imports/NeoChat/Menu/Timeline/qmldir @@ -2,3 +2,4 @@ module NeoChat.Menu.Timeline MessageDelegateContextMenu 1.0 MessageDelegateContextMenu.qml FileDelegateContextMenu 1.0 FileDelegateContextMenu.qml MessageSourceSheet 1.0 MessageSourceSheet.qml +ReportSheet 1.0 ReportSheet.qml diff --git a/imports/NeoChat/Page/RoomPage.qml b/imports/NeoChat/Page/RoomPage.qml index fb17b4c22..55e2910aa 100644 --- a/imports/NeoChat/Page/RoomPage.qml +++ b/imports/NeoChat/Page/RoomPage.qml @@ -105,17 +105,17 @@ Kirigami.ScrollablePage { function onShowMessage(messageType, message) { page.header.contentItem.text = message; page.header.contentItem.type = messageType === ActionsHandler.Error ? Kirigami.MessageType.Error : Kirigami.MessageType.Information; - page.header.contentItem.visible = true; + page.header.visible = true; } } header: QQC2.Control { height: visible ? implicitHeight : 0 - visible: contentItem.visible + visible: false padding: Kirigami.Units.smallSpacing contentItem: Kirigami.InlineMessage { showCloseButton: true - visible: false + visible: true } } @@ -177,6 +177,15 @@ Kirigami.ScrollablePage { } } + Connections { + target: currentRoom + function onPositiveMessage(message) { + page.header.contentItem.text = message; + page.header.contentItem.type = Kirigami.MessageType.Positive; + page.header.visible = true; + } + } + // hover actions on a delegate, activated in TimelineContainer.qml Connections { target: page.flickable @@ -582,7 +591,7 @@ Kirigami.ScrollablePage { function warning(title, message) { page.header.contentItem.text = `${title}
${message}`; page.header.contentItem.type = Kirigami.MessageType.Warning; - page.header.contentItem.visible = true; + page.header.visible = true; } function showUserDetail(user) { diff --git a/res.qrc b/res.qrc index 1de871c30..2e93d6216 100644 --- a/res.qrc +++ b/res.qrc @@ -78,6 +78,7 @@ imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml imports/NeoChat/Menu/Timeline/MessageSourceSheet.qml + imports/NeoChat/Menu/Timeline/ReportSheet.qml imports/NeoChat/Menu/RoomListContextMenu.qml qtquickcontrols2.conf imports/NeoChat/Component/glowdot.png diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 74e483e38..a3101c43c 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include "controller.h" #include "neochatconfig.h" @@ -1082,3 +1084,13 @@ void NeoChatRoom::updatePushNotificationState(QString type) m_currentPushNotificationState = PushNotificationState::Default; Q_EMIT pushNotificationStateChanged(m_currentPushNotificationState); } + +void NeoChatRoom::reportEvent(const QString &eventId, const QString &reason) +{ + auto job = connection()->callApi(id(), eventId, -50, reason); + connect(job, &BaseJob::finished, this, [this, job]() { + if (job->error() == BaseJob::Success) { + Q_EMIT positiveMessage(i18n("Report sent successfully.")); + } + }); +} diff --git a/src/neochatroom.h b/src/neochatroom.h index 4f8175990..2fb0b4b4b 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -147,6 +147,7 @@ public: Q_INVOKABLE QString htmlSafeName() const; Q_INVOKABLE QString htmlSafeDisplayName() const; Q_INVOKABLE void clearInvitationNotification(); + Q_INVOKABLE void reportEvent(const QString &eventId, const QString &reason); Q_INVOKABLE void setPushNotificationState(PushNotificationState::State state); @@ -192,6 +193,7 @@ Q_SIGNALS: void isInviteChanged(); void displayNameChanged(); void pushNotificationStateChanged(PushNotificationState::State state); + void positiveMessage(const QString &message); public Q_SLOTS: void uploadFile(const QUrl &url, const QString &body = QString());