File indexing completed on 2024-12-22 04:45:23
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "moderationuserdeletereportedmessagesjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 0011 #include <QJsonArray> 0012 #include <QJsonDocument> 0013 #include <QJsonObject> 0014 #include <QNetworkReply> 0015 using namespace RocketChatRestApi; 0016 ModerationUserDeleteReportedMessagesJob::ModerationUserDeleteReportedMessagesJob(QObject *parent) 0017 : RestApiAbstractJob(parent) 0018 { 0019 } 0020 0021 ModerationUserDeleteReportedMessagesJob::~ModerationUserDeleteReportedMessagesJob() = default; 0022 0023 bool ModerationUserDeleteReportedMessagesJob::start() 0024 { 0025 if (!canStart()) { 0026 deleteLater(); 0027 return false; 0028 } 0029 addStartRestApiInfo("ModerationUserDeleteReportedMessagesJob::start"); 0030 submitPostRequest(json()); 0031 0032 return true; 0033 } 0034 0035 void ModerationUserDeleteReportedMessagesJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0036 { 0037 const QJsonObject replyObject = replyJson.object(); 0038 0039 if (replyObject[QLatin1String("success")].toBool()) { 0040 addLoggerInfo(QByteArrayLiteral("ModerationUserDeleteReportedMessagesJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0041 Q_EMIT moderationUserDeleteReportedMessagesDone(); 0042 } else { 0043 emitFailedMessage(replyErrorString, replyObject); 0044 addLoggerWarning(QByteArrayLiteral("ModerationUserDeleteReportedMessagesJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 } 0046 } 0047 0048 QString ModerationUserDeleteReportedMessagesJob::userIdForMessages() const 0049 { 0050 return mUserIdForMessages; 0051 } 0052 0053 void ModerationUserDeleteReportedMessagesJob::setUserIdForMessages(const QString &newUserIdForMessages) 0054 { 0055 mUserIdForMessages = newUserIdForMessages; 0056 } 0057 0058 bool ModerationUserDeleteReportedMessagesJob::requireHttpAuthentication() const 0059 { 0060 return true; 0061 } 0062 0063 bool ModerationUserDeleteReportedMessagesJob::canStart() const 0064 { 0065 if (!RestApiAbstractJob::canStart()) { 0066 return false; 0067 } 0068 if (mUserIdForMessages.isEmpty()) { 0069 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ModerationUserDeleteReportedMessagesJob: mUserIdForMessages is empty"; 0070 return false; 0071 } 0072 return true; 0073 } 0074 0075 QNetworkRequest ModerationUserDeleteReportedMessagesJob::request() const 0076 { 0077 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ModerationUserDeleteReportedMessages); 0078 QNetworkRequest request(url); 0079 addAuthRawHeader(request); 0080 addRequestAttribute(request); 0081 return request; 0082 } 0083 0084 QJsonDocument ModerationUserDeleteReportedMessagesJob::json() const 0085 { 0086 QJsonObject jsonObj; 0087 jsonObj[QLatin1String("userId")] = mUserIdForMessages; 0088 const QJsonDocument postData = QJsonDocument(jsonObj); 0089 return postData; 0090 } 0091 0092 #include "moc_moderationuserdeletereportedmessagesjob.cpp"