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

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "resetowne2ekeyjob.h"
0008 #include "restapimethod.h"
0009 
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QNetworkReply>
0013 using namespace RocketChatRestApi;
0014 ResetOwnE2eKeyJob::ResetOwnE2eKeyJob(QObject *parent)
0015     : RestApiAbstractJob(parent)
0016 {
0017 }
0018 
0019 ResetOwnE2eKeyJob::~ResetOwnE2eKeyJob() = default;
0020 
0021 bool ResetOwnE2eKeyJob::start()
0022 {
0023     if (!canStart()) {
0024         deleteLater();
0025         return false;
0026     }
0027     addStartRestApiInfo("ResetOwnE2eKeyJob::start");
0028     submitPostRequest(json());
0029     return true;
0030 }
0031 
0032 void ResetOwnE2eKeyJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0033 {
0034     const QJsonObject replyObject = replyJson.object();
0035 
0036     if (replyObject[QLatin1String("success")].toBool()) {
0037         addLoggerInfo(QByteArrayLiteral("ResetOwnE2eKeyJob: success: ") + replyJson.toJson(QJsonDocument::Indented));
0038         Q_EMIT resetE2eKeyDone(replyObject);
0039     } else {
0040         emitFailedMessage(replyErrorString, replyObject);
0041         addLoggerWarning(QByteArrayLiteral("ResetOwnE2eKeyJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented));
0042     }
0043 }
0044 
0045 bool ResetOwnE2eKeyJob::requireHttpAuthentication() const
0046 {
0047     return true;
0048 }
0049 
0050 bool ResetOwnE2eKeyJob::canStart() const
0051 {
0052     if (!RestApiAbstractJob::canStart()) {
0053         return false;
0054     }
0055     return true;
0056 }
0057 
0058 QNetworkRequest ResetOwnE2eKeyJob::request() const
0059 {
0060     const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::E2EResetOwnE2EKey);
0061     QNetworkRequest request(url);
0062     addAuthRawHeader(request);
0063     addRequestAttribute(request);
0064     return request;
0065 }
0066 
0067 QJsonDocument ResetOwnE2eKeyJob::json() const
0068 {
0069     QJsonObject jsonObj;
0070     // TODO
0071     const QJsonDocument postData = QJsonDocument(jsonObj);
0072     return postData;
0073 }
0074 
0075 #include "moc_resetowne2ekeyjob.cpp"