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