File indexing completed on 2025-01-12 04:33:55
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "reportmessagejob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 0011 #include <QJsonDocument> 0012 #include <QJsonObject> 0013 #include <QNetworkReply> 0014 using namespace RocketChatRestApi; 0015 ReportMessageJob::ReportMessageJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 ReportMessageJob::~ReportMessageJob() = default; 0021 0022 bool ReportMessageJob::start() 0023 { 0024 if (!canStart()) { 0025 deleteLater(); 0026 return false; 0027 } 0028 addStartRestApiInfo("ReportMessageJob::start"); 0029 submitPostRequest(json()); 0030 0031 return true; 0032 } 0033 0034 void ReportMessageJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0035 { 0036 auto reply = mReply; 0037 if (reply) { 0038 const QByteArray data = reply->readAll(); 0039 addLoggerInfo(QByteArrayLiteral("ReportMessageJob: success: ") + data); 0040 Q_EMIT reportMessageDone(); 0041 reply->deleteLater(); 0042 } 0043 deleteLater(); 0044 } 0045 0046 QString ReportMessageJob::reportMessage() const 0047 { 0048 return mReportMessage; 0049 } 0050 0051 void ReportMessageJob::setReportMessage(const QString &reportMessage) 0052 { 0053 mReportMessage = reportMessage; 0054 } 0055 0056 bool ReportMessageJob::requireHttpAuthentication() const 0057 { 0058 return true; 0059 } 0060 0061 bool ReportMessageJob::canStart() const 0062 { 0063 if (!RestApiAbstractJob::canStart()) { 0064 return false; 0065 } 0066 if (mMessageId.isEmpty()) { 0067 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ReportMessageJob: mMessageId is empty"; 0068 return false; 0069 } 0070 if (mReportMessage.isEmpty()) { 0071 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ReportMessageJob: mReportMessage is empty"; 0072 return false; 0073 } 0074 return true; 0075 } 0076 0077 QNetworkRequest ReportMessageJob::request() const 0078 { 0079 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChatReportMessage); 0080 QNetworkRequest request(url); 0081 addAuthRawHeader(request); 0082 addRequestAttribute(request); 0083 return request; 0084 } 0085 0086 QString ReportMessageJob::messageId() const 0087 { 0088 return mMessageId; 0089 } 0090 0091 void ReportMessageJob::setMessageId(const QString &messageId) 0092 { 0093 mMessageId = messageId; 0094 } 0095 0096 QJsonDocument ReportMessageJob::json() const 0097 { 0098 QJsonObject jsonObj; 0099 jsonObj[QLatin1String("messageId")] = mMessageId; 0100 jsonObj[QLatin1String("description")] = mReportMessage; 0101 0102 const QJsonDocument postData = QJsonDocument(jsonObj); 0103 return postData; 0104 } 0105 0106 #include "moc_reportmessagejob.cpp"