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 "moderationreportinfojob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 #include <QUrlQuery> 0014 using namespace RocketChatRestApi; 0015 ModerationReportInfoJob::ModerationReportInfoJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 ModerationReportInfoJob::~ModerationReportInfoJob() = default; 0021 0022 bool ModerationReportInfoJob::requireHttpAuthentication() const 0023 { 0024 return true; 0025 } 0026 0027 bool ModerationReportInfoJob::start() 0028 { 0029 if (!canStart()) { 0030 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start get report info job"; 0031 deleteLater(); 0032 return false; 0033 } 0034 submitGetRequest(); 0035 0036 addStartRestApiInfo(QByteArrayLiteral("ModerationReportJob: get report info starting")); 0037 return true; 0038 } 0039 0040 void ModerationReportInfoJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0041 { 0042 const QJsonObject replyObject = replyJson.object(); 0043 if (replyObject[QLatin1String("success")].toBool()) { 0044 addLoggerInfo(QByteArrayLiteral("ModerationReportJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 Q_EMIT moderationReportInfoDone(replyObject); 0046 } else { 0047 emitFailedMessage(replyErrorString, replyObject); 0048 addLoggerWarning(QByteArrayLiteral("ModerationReportJob: Problem when we tried to get report info : ") + replyJson.toJson(QJsonDocument::Indented)); 0049 } 0050 } 0051 0052 QString ModerationReportInfoJob::reportId() const 0053 { 0054 return mReportId; 0055 } 0056 0057 void ModerationReportInfoJob::setReportId(const QString &newReportId) 0058 { 0059 mReportId = newReportId; 0060 } 0061 0062 QNetworkRequest ModerationReportInfoJob::request() const 0063 { 0064 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ModerationReportInfo); 0065 QUrlQuery queryUrl; 0066 queryUrl.addQueryItem(QStringLiteral("reportId"), mReportId); 0067 url.setQuery(queryUrl); 0068 QNetworkRequest request(url); 0069 addAuthRawHeader(request); 0070 addRequestAttribute(request, false); 0071 0072 return request; 0073 } 0074 0075 bool ModerationReportInfoJob::canStart() const 0076 { 0077 if (!RestApiAbstractJob::canStart()) { 0078 return false; 0079 } 0080 if (mReportId.isEmpty()) { 0081 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "mReportId is empty"; 0082 return false; 0083 } 0084 return true; 0085 } 0086 0087 #include "moc_moderationreportinfojob.cpp"