Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add report message functionality #1539

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
LorenDB marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -333,6 +333,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