Skip to content

Commit

Permalink
Merge pull request #1539 from Nheko-Reborn/issue1410
Browse files Browse the repository at this point in the history
Add report message functionality
  • Loading branch information
deepbluev7 authored Oct 26, 2023
2 parents 904d3f2 + bb971b0 commit 1512810
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare(
MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG 8936559c00542528a7776d774fccb7ff674c9c7f
GIT_TAG f878e29420c037f45b575fbd29a11cabce3c010a
)
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
Expand Down Expand Up @@ -772,6 +772,7 @@ set(QML_SOURCES
resources/qml/dialogs/RawMessageDialog.qml
resources/qml/dialogs/ReadReceipts.qml
resources/qml/dialogs/ReCaptchaDialog.qml
resources/qml/dialogs/ReportMessage.qml
resources/qml/dialogs/RoomDirectory.qml
resources/qml/dialogs/RoomMembers.qml
resources/qml/dialogs/AllowedRoomsSettingsDialog.qml
Expand Down
2 changes: 1 addition & 1 deletion im.nheko.Nheko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ modules:
buildsystem: cmake-ninja
name: mtxclient
sources:
- commit: 8936559c00542528a7776d774fccb7ff674c9c7f
- commit: 6e01c75fccc2724fcdfe7a7b1a13547522eb8753
#tag: v0.9.2
type: git
url: https://github.com/Nheko-Reborn/mtxclient.git
Expand Down
16 changes: 16 additions & 0 deletions resources/qml/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ Item {
}
}
}
Component {
id: reportDialog

ReportMessage {}
}

Platform.MenuItem {
enabled: visible
text: qsTr("Go to &message")
Expand Down Expand Up @@ -521,6 +527,16 @@ Item {
timelineRoot.destroyOnClose(dialog);
}
}
Platform.MenuItem {
text: qsTr("Report message")
enabled: visible
onTriggered: function () {
var dialog = reportDialog.createObject(timelineRoot, {"eventId": messageContextMenu.eventId});
dialog.show();
dialog.forceActiveFocus();
timelineRoot.destroyOnClose(dialog);
}
}
Platform.MenuItem {
enabled: visible
text: qsTr("&Save as")
Expand Down
85 changes: 85 additions & 0 deletions resources/qml/dialogs/ReportMessage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import im.nheko

ApplicationWindow {
required property string eventId

width: 400
height: gl.implicitHeight + 2 * Nheko.paddingMedium
title: qsTr("Report message")

GridLayout {
id: gl

columnSpacing: Nheko.paddingMedium
rowSpacing: Nheko.paddingMedium
columns: 2
anchors.fill: parent
anchors.margins: Nheko.paddingMedium

Label {
Layout.columnSpan: 2
Layout.fillWidth: true
wrapMode: Label.WordWrap
text: qsTr("This message you are reporting will be sent to your server administrator for review. Please note that not all server administrators review reported content. You should also ask a room moderator to remove the content if necessary.")
}

Label {
text: qsTr("Enter your reason for reporting:")
}

TextField {
id: reason

Layout.fillWidth: true
}

Label {
text: qsTr("How bad is the message?")
}

Slider {
id: score

from: 0
to: -100
stepSize: 25
snapMode: Slider.SnapAlways
Layout.fillWidth: true
}

Item {}

Label {
text: {
if (score.value === 0)
return qsTr("Not bad")
else if (score.value === -25)
return qsTr("Mild")
else if (score.value === -50)
return qsTr("Bad")
else if (score.value === -75)
return qsTr("Serious")
else if (score.value === -100)
return qsTr("Extremely serious")
}
}

DialogButtonBox {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignRight
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
onAccepted: {
room.reportEvent(eventId, reason.text, score.value);
close();
}
onRejected: close()
}
}
}
8 changes: 8 additions & 0 deletions src/timeline/TimelineModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,14 @@ TimelineModel::redactAllFromUser(const QString &userid, const QString &reason)
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}

void
TimelineModel::reportEvent(const QString &eventId, const QString &reason, const int score)
{
http::client()->report_event(
room_id_.toStdString(), eventId.toStdString(), reason.toStdString(), score);
}

void
TimelineModel::redactEvent(const QString &id, const QString &reason)
{
Expand Down
2 changes: 2 additions & 0 deletions src/timeline/TimelineModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ class TimelineModel final : public QAbstractListModel
Q_INVOKABLE void showReadReceipts(const QString &id);
Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = "");
Q_INVOKABLE void redactAllFromUser(const QString &userid, const QString &reason = "");
Q_INVOKABLE void
reportEvent(const QString &eventId, const QString &reason = {}, const int score = -50);
Q_INVOKABLE int idToIndex(const QString &id) const;
Q_INVOKABLE QString indexToId(int index) const;
Q_INVOKABLE void openMedia(const QString &eventId);
Expand Down

0 comments on commit 1512810

Please sign in to comment.