File indexing completed on 2024-12-22 04:45:21
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 "groupopenjob.h" 0008 0009 #include "restapimethod.h" 0010 #include "rocketchatqtrestapi_debug.h" 0011 #include <QJsonDocument> 0012 #include <QJsonObject> 0013 #include <QNetworkReply> 0014 0015 using namespace RocketChatRestApi; 0016 GroupOpenJob::GroupOpenJob(QObject *parent) 0017 : ChannelGroupBaseJob(parent) 0018 { 0019 } 0020 0021 GroupOpenJob::~GroupOpenJob() = default; 0022 0023 bool GroupOpenJob::start() 0024 { 0025 if (!canStart()) { 0026 deleteLater(); 0027 return false; 0028 } 0029 addStartRestApiInfo("GroupOpenJob::start"); 0030 submitPostRequest(json()); 0031 0032 return true; 0033 } 0034 0035 void GroupOpenJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0036 { 0037 const QJsonObject replyObject = replyJson.object(); 0038 0039 if (replyObject[QLatin1String("success")].toBool()) { 0040 addLoggerInfo(QByteArrayLiteral("GroupOpenJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0041 Q_EMIT groupOpenDone(replyObject, channelGroupInfo()); 0042 } else { 0043 emitFailedMessage(replyErrorString, replyObject); 0044 addLoggerWarning(QByteArrayLiteral("GroupOpenJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 } 0046 } 0047 0048 bool GroupOpenJob::requireHttpAuthentication() const 0049 { 0050 return true; 0051 } 0052 0053 bool GroupOpenJob::canStart() const 0054 { 0055 if (!RestApiAbstractJob::canStart()) { 0056 return false; 0057 } 0058 if (!hasIdentifier()) { 0059 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GroupOpenJob: RoomId and RoomName are empty"; 0060 return false; 0061 } 0062 return true; 0063 } 0064 0065 QJsonDocument GroupOpenJob::json() const 0066 { 0067 QJsonObject jsonObj; 0068 generateJson(jsonObj); 0069 0070 const QJsonDocument postData = QJsonDocument(jsonObj); 0071 return postData; 0072 } 0073 0074 QNetworkRequest GroupOpenJob::request() const 0075 { 0076 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsOpen); 0077 QNetworkRequest request(url); 0078 addAuthRawHeader(request); 0079 addRequestAttribute(request); 0080 return request; 0081 } 0082 0083 #include "moc_groupopenjob.cpp"