File indexing completed on 2024-12-22 04:45:27
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 "teamconverttochanneljob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 0011 #include <QJsonArray> 0012 #include <QJsonDocument> 0013 #include <QJsonObject> 0014 #include <QNetworkReply> 0015 using namespace RocketChatRestApi; 0016 TeamConvertToChannelJob::TeamConvertToChannelJob(QObject *parent) 0017 : RestApiAbstractJob(parent) 0018 { 0019 } 0020 0021 TeamConvertToChannelJob::~TeamConvertToChannelJob() = default; 0022 0023 bool TeamConvertToChannelJob::start() 0024 { 0025 if (!canStart()) { 0026 deleteLater(); 0027 return false; 0028 } 0029 addStartRestApiInfo("TeamConvertToChannelJob::start"); 0030 submitPostRequest(json()); 0031 0032 return true; 0033 } 0034 0035 void TeamConvertToChannelJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0036 { 0037 const QJsonObject replyObject = replyJson.object(); 0038 0039 if (replyObject[QLatin1String("success")].toBool()) { 0040 addLoggerInfo(QByteArrayLiteral("TeamConvertToChannelJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0041 Q_EMIT teamConvertToChannelDone(); 0042 } else { 0043 emitFailedMessage(replyErrorString, replyObject); 0044 addLoggerWarning(QByteArrayLiteral("TeamConvertToChannelJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 } 0046 } 0047 0048 const QStringList &TeamConvertToChannelJob::roomsToRemove() const 0049 { 0050 return mRoomsToRemove; 0051 } 0052 0053 void TeamConvertToChannelJob::setRoomsToRemove(const QStringList &newRoomsToRemove) 0054 { 0055 mRoomsToRemove = newRoomsToRemove; 0056 } 0057 0058 QString TeamConvertToChannelJob::teamId() const 0059 { 0060 return mTeamId; 0061 } 0062 0063 void TeamConvertToChannelJob::setTeamId(const QString &teamId) 0064 { 0065 mTeamId = teamId; 0066 } 0067 0068 bool TeamConvertToChannelJob::requireHttpAuthentication() const 0069 { 0070 return true; 0071 } 0072 0073 bool TeamConvertToChannelJob::canStart() const 0074 { 0075 if (!RestApiAbstractJob::canStart()) { 0076 return false; 0077 } 0078 if (mTeamId.isEmpty()) { 0079 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "TeamConvertToChannelJob: mTeamId is empty"; 0080 return false; 0081 } 0082 return true; 0083 } 0084 0085 QNetworkRequest TeamConvertToChannelJob::request() const 0086 { 0087 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::TeamsConvertToChannel); 0088 QNetworkRequest request(url); 0089 addAuthRawHeader(request); 0090 addRequestAttribute(request); 0091 return request; 0092 } 0093 0094 QJsonDocument TeamConvertToChannelJob::json() const 0095 { 0096 QJsonObject jsonObj; 0097 jsonObj[QLatin1String("teamId")] = mTeamId; 0098 if (!mRoomsToRemove.isEmpty()) { 0099 jsonObj[QLatin1String("roomsToRemove")] = QJsonArray::fromStringList(mRoomsToRemove); 0100 } 0101 const QJsonDocument postData = QJsonDocument(jsonObj); 0102 return postData; 0103 } 0104 0105 #include "moc_teamconverttochanneljob.cpp"