File indexing completed on 2024-05-05 17:00:19
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 "channellistjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 using namespace RocketChatRestApi; 0014 ChannelListJob::ChannelListJob(QObject *parent) 0015 : RestApiAbstractJob(parent) 0016 { 0017 } 0018 0019 ChannelListJob::~ChannelListJob() = default; 0020 0021 bool ChannelListJob::start() 0022 { 0023 if (!canStart()) { 0024 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start channel list job"; 0025 deleteLater(); 0026 return false; 0027 } 0028 0029 submitGetRequest(); 0030 addStartRestApiInfo(QByteArrayLiteral("ChannelListJob: ask channel list")); 0031 return false; 0032 } 0033 0034 void ChannelListJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0035 { 0036 const QJsonObject replyObject = replyJson.object(); 0037 if (replyObject[QLatin1String("success")].toBool()) { 0038 addLoggerInfo(QByteArrayLiteral("ChannelListJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0039 Q_EMIT channelListDone(replyObject); 0040 } else { 0041 emitFailedMessage(replyErrorString, replyObject); 0042 addLoggerWarning(QByteArrayLiteral("ChannelListJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0043 } 0044 } 0045 0046 QNetworkRequest ChannelListJob::request() const 0047 { 0048 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsList); 0049 QNetworkRequest request(url); 0050 addAuthRawHeader(request); 0051 return request; 0052 } 0053 0054 bool ChannelListJob::requireHttpAuthentication() const 0055 { 0056 return true; 0057 } 0058 0059 #include "moc_channellistjob.cpp"