File indexing completed on 2024-12-22 04:45:20

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 "loademojicustomjob.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 LoadEmojiCustomJob::LoadEmojiCustomJob(QObject *parent)
0016     : RestApiAbstractJob(parent)
0017 {
0018 }
0019 
0020 LoadEmojiCustomJob::~LoadEmojiCustomJob() = default;
0021 
0022 bool LoadEmojiCustomJob::start()
0023 {
0024     if (!canStart()) {
0025         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start LoadEmojiCustomJob job";
0026         deleteLater();
0027         return false;
0028     }
0029     submitGetRequest();
0030     addStartRestApiInfo(QByteArrayLiteral("LoadEmojiCustomJob: Load Emoji custom"));
0031 
0032     return true;
0033 }
0034 
0035 void LoadEmojiCustomJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0036 {
0037     const QJsonObject replyObject = replyJson.object();
0038 
0039     if (replyObject[QLatin1String("success")].toBool()) {
0040         addLoggerInfo(QByteArrayLiteral("LoadEmojiCustomJob done: ") + replyJson.toJson(QJsonDocument::Indented));
0041         Q_EMIT loadEmojiCustomDone(replyObject);
0042     } else {
0043         emitFailedMessage(replyErrorString, replyObject);
0044         addLoggerWarning(QByteArrayLiteral("LoadEmojiCustomJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented));
0045     }
0046 }
0047 
0048 bool LoadEmojiCustomJob::requireHttpAuthentication() const
0049 {
0050     return true;
0051 }
0052 
0053 bool LoadEmojiCustomJob::hasQueryParameterSupport() const
0054 {
0055     // Since 0.71
0056     return true;
0057 }
0058 
0059 QNetworkRequest LoadEmojiCustomJob::request() const
0060 {
0061     QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::LoadEmojiCustom);
0062     QNetworkRequest req(url);
0063     QUrlQuery queryUrl;
0064     addQueryParameter(queryUrl);
0065     if (!queryUrl.isEmpty()) {
0066         url.setQuery(queryUrl);
0067     }
0068     addAuthRawHeader(req);
0069     return req;
0070 }
0071 
0072 #include "moc_loademojicustomjob.cpp"