Add support for reporting rooms and users
This was added in recent Matrix versions, and a desperately needed feature.
This commit is contained in:
@@ -293,5 +293,25 @@ Kirigami.Dialog {
|
||||
icon.name: "username-copy"
|
||||
onClicked: Clipboard.saveText("https://matrix.to/#/" + root.user.id)
|
||||
}
|
||||
|
||||
FormCard.FormButtonDelegate {
|
||||
text: i18nc("@action:button 'Report' as in 'Report this user to the administrators'", "Report…")
|
||||
icon.name: "dialog-warning-symbolic"
|
||||
visible: root.connection.supportsMatrixSpecVersion("v1.13")
|
||||
onClicked: {
|
||||
let dialog = ((QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow).pageStack as Kirigami.PageRow).pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), {
|
||||
title: i18nc("@title:dialog", "Report User"),
|
||||
placeholder: i18nc("@info:placeholder", "Reason for reporting this user"),
|
||||
icon: "dialog-warning-symbolic",
|
||||
actionText: i18nc("@action:button 'Report' as in 'Report this user to the administrators'", "Report")
|
||||
}, {
|
||||
title: i18nc("@title", "Report User"),
|
||||
width: Kirigami.Units.gridUnit * 25
|
||||
}) as ReasonDialog;
|
||||
dialog.accepted.connect(reason => {
|
||||
root.connection.reportUser(root.user.id, reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ target_sources(LibNeoChat PRIVATE
|
||||
events/imagepackevent.cpp
|
||||
events/pollevent.cpp
|
||||
jobs/neochatgetcommonroomsjob.cpp
|
||||
jobs/neochatreportroomjob.cpp
|
||||
jobs/neochatreportuserjob.cpp
|
||||
models/actionsmodel.cpp
|
||||
models/completionmodel.cpp
|
||||
models/completionproxymodel.cpp
|
||||
|
||||
14
src/libneochat/jobs/neochatreportroomjob.cpp
Normal file
14
src/libneochat/jobs/neochatreportroomjob.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "neochatreportroomjob.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
NeochatReportRoomJob::NeochatReportRoomJob(const QString &userId, const QString &reason)
|
||||
: BaseJob(HttpVerb::Post, u"ReportRoomJob"_s, makePath(" /_matrix/client/v3/", userId, "/report"))
|
||||
{
|
||||
QJsonObject _dataJson;
|
||||
addParam<IfNotEmpty>(_dataJson, "reason"_L1, reason);
|
||||
setRequestData({_dataJson});
|
||||
}
|
||||
13
src/libneochat/jobs/neochatreportroomjob.h
Normal file
13
src/libneochat/jobs/neochatreportroomjob.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Quotient/jobs/basejob.h>
|
||||
|
||||
// TODO: Remove once libQuotient updates to Matrix API v1.14
|
||||
class NeochatReportRoomJob : public Quotient::BaseJob
|
||||
{
|
||||
public:
|
||||
explicit NeochatReportRoomJob(const QString &roomId, const QString &reason);
|
||||
};
|
||||
14
src/libneochat/jobs/neochatreportuserjob.cpp
Normal file
14
src/libneochat/jobs/neochatreportuserjob.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "neochatreportuserjob.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
NeochatReportUserJob::NeochatReportUserJob(const QString &userId, const QString &reason)
|
||||
: BaseJob(HttpVerb::Post, u"ReportUserJob"_s, makePath("/_matrix/client/v3/users/", userId, "/report"))
|
||||
{
|
||||
QJsonObject _dataJson;
|
||||
addParam<IfNotEmpty>(_dataJson, "reason"_L1, reason);
|
||||
setRequestData({_dataJson});
|
||||
}
|
||||
13
src/libneochat/jobs/neochatreportuserjob.h
Normal file
13
src/libneochat/jobs/neochatreportuserjob.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Quotient/jobs/basejob.h>
|
||||
|
||||
// TODO: Remove once libQuotient updates to Matrix API v1.14
|
||||
class NeochatReportUserJob : public Quotient::BaseJob
|
||||
{
|
||||
public:
|
||||
explicit NeochatReportUserJob(const QString &userId, const QString &reason);
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QImageReader>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#include "jobs/neochatreportuserjob.h"
|
||||
#include "neochatroom.h"
|
||||
#include "spacehierarchycache.h"
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@
|
||||
#include "roomlastmessageprovider.h"
|
||||
#include "spacehierarchycache.h"
|
||||
#include "urlhelper.h"
|
||||
#include "jobs/neochatreportroomjob.h"
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
#include <KIO/Job>
|
||||
#include <KIO/JobTracker>
|
||||
#endif
|
||||
|
||||
#include <KJobTrackerInterface>
|
||||
#include <KLocalizedString>
|
||||
|
||||
@@ -1838,4 +1838,9 @@ QString NeoChatRoom::pinnedMessage() const
|
||||
return m_pinnedMessage;
|
||||
}
|
||||
|
||||
void NeoChatRoom::report(const QString &reason)
|
||||
{
|
||||
connection()->callApi<NeochatReportRoomJob>(id(), reason);
|
||||
}
|
||||
|
||||
#include "moc_neochatroom.cpp"
|
||||
|
||||
@@ -622,6 +622,11 @@ public:
|
||||
*/
|
||||
QString pinnedMessage() const;
|
||||
|
||||
/**
|
||||
* @brief Send a report about this room.
|
||||
*/
|
||||
Q_INVOKABLE void report(const QString &reason);
|
||||
|
||||
private:
|
||||
bool m_visible = false;
|
||||
|
||||
|
||||
@@ -150,6 +150,26 @@ KirigamiComponents.ConvergentContextMenu {
|
||||
separator: true
|
||||
}
|
||||
|
||||
Kirigami.Action {
|
||||
text: i18nc("@action:button 'Report' as in 'Report this room to the administrators'", "Report…")
|
||||
icon.name: "dialog-warning-symbolic"
|
||||
visible: root.connection.supportsMatrixSpecVersion("v1.13")
|
||||
onTriggered: {
|
||||
let dialog = (root.Kirigami.PageStack.pageStack as Kirigami.PageRow).pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ReasonDialog'), {
|
||||
title: i18nc("@title:dialog", "Report Room"),
|
||||
placeholder: i18nc("@info:placeholder", "Reason for reporting this room"),
|
||||
icon: "dialog-warning-symbolic",
|
||||
actionText: i18nc("@action:button 'Report' as in 'Report this room to the administrators'", "Report")
|
||||
}, {
|
||||
title: i18nc("@title", "Report Room"),
|
||||
width: Kirigami.Units.gridUnit * 25
|
||||
}) as ReasonDialog;
|
||||
dialog.accepted.connect(reason => {
|
||||
currentRoom.report(reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.Action {
|
||||
text: i18nc("@action:inmenu", "Leave Room…")
|
||||
icon.name: "go-previous"
|
||||
|
||||
Reference in New Issue
Block a user