File indexing completed on 2024-12-22 04:45:21
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "groupremovemoderatorjob.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 GroupRemoveModeratorJob::GroupRemoveModeratorJob(QObject *parent) 0016 : ChannelGroupBaseJob(parent) 0017 { 0018 } 0019 0020 GroupRemoveModeratorJob::~GroupRemoveModeratorJob() = default; 0021 0022 bool GroupRemoveModeratorJob::start() 0023 { 0024 if (!canStart()) { 0025 deleteLater(); 0026 return false; 0027 } 0028 addStartRestApiInfo("GroupRemoveModeratorJob::start"); 0029 submitPostRequest(json()); 0030 0031 return true; 0032 } 0033 0034 void GroupRemoveModeratorJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0035 { 0036 const QJsonObject replyObject = replyJson.object(); 0037 0038 if (replyObject[QLatin1String("success")].toBool()) { 0039 addLoggerInfo(QByteArrayLiteral("GroupRemoveModeratorJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0040 Q_EMIT removeModeratorDone(); 0041 } else { 0042 emitFailedMessage(replyErrorString, replyObject); 0043 addLoggerWarning(QByteArrayLiteral("GroupRemoveModeratorJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0044 } 0045 } 0046 0047 QString GroupRemoveModeratorJob::removeUserId() const 0048 { 0049 return mRemoveUserId; 0050 } 0051 0052 void GroupRemoveModeratorJob::setRemoveUserId(const QString &removeUserId) 0053 { 0054 mRemoveUserId = removeUserId; 0055 } 0056 0057 bool GroupRemoveModeratorJob::requireHttpAuthentication() const 0058 { 0059 return true; 0060 } 0061 0062 bool GroupRemoveModeratorJob::canStart() const 0063 { 0064 if (mRemoveUserId.isEmpty()) { 0065 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GroupRemoveModeratorJob: remove userid is empty"; 0066 return false; 0067 } 0068 if (hasIdentifier()) { 0069 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "GroupRemoveModeratorJob: RoomId is empty"; 0070 return false; 0071 } 0072 if (!RestApiAbstractJob::canStart()) { 0073 return false; 0074 } 0075 return true; 0076 } 0077 0078 QJsonDocument GroupRemoveModeratorJob::json() const 0079 { 0080 QJsonObject jsonObj; 0081 generateJson(jsonObj); 0082 jsonObj[QLatin1String("userId")] = removeUserId(); 0083 0084 const QJsonDocument postData = QJsonDocument(jsonObj); 0085 return postData; 0086 } 0087 0088 QNetworkRequest GroupRemoveModeratorJob::request() const 0089 { 0090 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::GroupsRemoveModerator); 0091 QNetworkRequest request(url); 0092 addAuthRawHeader(request); 0093 addRequestAttribute(request); 0094 return request; 0095 } 0096 0097 #include "moc_groupremovemoderatorjob.cpp"