File indexing completed on 2024-12-22 04:45:14
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "channelgetcountersjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 using namespace RocketChatRestApi; 0014 ChannelGetCountersJob::ChannelGetCountersJob(QObject *parent) 0015 : ChannelGroupBaseJob(parent) 0016 { 0017 } 0018 0019 ChannelGetCountersJob::~ChannelGetCountersJob() = default; 0020 0021 bool ChannelGetCountersJob::canStart() const 0022 { 0023 if (!hasIdentifier()) { 0024 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelGetCountersJob: RoomId and RoomName are empty"; 0025 return false; 0026 } 0027 if (!RestApiAbstractJob::canStart()) { 0028 return false; 0029 } 0030 return true; 0031 } 0032 0033 bool ChannelGetCountersJob::start() 0034 { 0035 if (!canStart()) { 0036 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start server info job"; 0037 deleteLater(); 0038 return false; 0039 } 0040 0041 submitGetRequest(); 0042 addStartRestApiInfo("ChannelGetCountersJob::start"); 0043 0044 return true; 0045 } 0046 0047 QNetworkRequest ChannelGetCountersJob::request() const 0048 { 0049 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsCounters); 0050 addQueryItem(url); 0051 QNetworkRequest request(url); 0052 addAuthRawHeader(request); 0053 addRequestAttribute(request, false); 0054 0055 return request; 0056 } 0057 0058 bool ChannelGetCountersJob::requireHttpAuthentication() const 0059 { 0060 return true; 0061 } 0062 0063 void ChannelGetCountersJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0064 { 0065 const QJsonObject replyObject = replyJson.object(); 0066 if (replyObject[QLatin1String("success")].toBool()) { 0067 addLoggerInfo(QByteArrayLiteral("ChannelGetCountersJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0068 Q_EMIT channelGetCountersDone(replyObject, channelGroupInfo()); 0069 } else { 0070 emitFailedMessage(replyErrorString, replyObject); 0071 addLoggerWarning(QByteArrayLiteral("ChannelGetCountersJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0072 } 0073 } 0074 0075 bool ChannelGetCountersJob::hasQueryParameterSupport() const 0076 { 0077 return false; 0078 } 0079 0080 #include "moc_channelgetcountersjob.cpp"