File indexing completed on 2024-12-22 04:45:26
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "publicsettingsjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 using namespace RocketChatRestApi; 0014 PublicSettingsJob::PublicSettingsJob(QObject *parent) 0015 : RestApiAbstractJob(parent) 0016 { 0017 } 0018 0019 PublicSettingsJob::~PublicSettingsJob() = default; 0020 0021 bool PublicSettingsJob::start() 0022 { 0023 if (!canStart()) { 0024 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start PublicSettingsJob job"; 0025 deleteLater(); 0026 return false; 0027 } 0028 submitGetRequest(); 0029 addStartRestApiInfo(QByteArrayLiteral("PublicSettingsJob: Ask public info")); 0030 0031 return true; 0032 } 0033 0034 void PublicSettingsJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0035 { 0036 const QJsonObject replyObject = replyJson.object(); 0037 0038 if (replyObject[QLatin1String("success")].toBool()) { 0039 addLoggerInfo(QByteArrayLiteral("PublicSettingsJob done: ") + replyJson.toJson(QJsonDocument::Indented)); 0040 Q_EMIT publicSettingsDone(replyObject); 0041 } else { 0042 emitFailedMessage(replyErrorString, replyObject); 0043 addLoggerWarning(QByteArrayLiteral("PublicSettingsJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0044 } 0045 } 0046 0047 bool PublicSettingsJob::requireHttpAuthentication() const 0048 { 0049 return false; 0050 } 0051 0052 QNetworkRequest PublicSettingsJob::request() const 0053 { 0054 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::SettingsPublic); 0055 QNetworkRequest req(url); 0056 addAuthRawHeader(req); 0057 return req; 0058 } 0059 0060 #include "moc_publicsettingsjob.cpp"