File indexing completed on 2024-12-22 04:45:14
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 "channelgetallusermentionsjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 #include <QUrlQuery> 0014 using namespace RocketChatRestApi; 0015 ChannelGetAllUserMentionsJob::ChannelGetAllUserMentionsJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 ChannelGetAllUserMentionsJob::~ChannelGetAllUserMentionsJob() = default; 0021 0022 bool ChannelGetAllUserMentionsJob::canStart() const 0023 { 0024 if (mRoomId.isEmpty()) { 0025 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "ChannelGetAllUserMentionsJob: RoomId is empty"; 0026 return false; 0027 } 0028 if (!RestApiAbstractJob::canStart()) { 0029 return false; 0030 } 0031 return true; 0032 } 0033 0034 bool ChannelGetAllUserMentionsJob::start() 0035 { 0036 if (!canStart()) { 0037 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start server info job"; 0038 deleteLater(); 0039 return false; 0040 } 0041 0042 submitGetRequest(); 0043 addStartRestApiInfo("ChannelGetAllUserMentionsJob::start"); 0044 0045 return true; 0046 } 0047 0048 QNetworkRequest ChannelGetAllUserMentionsJob::request() const 0049 { 0050 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::ChannelsGetAllUserMentionsByChannel); 0051 QUrlQuery queryUrl; 0052 queryUrl.addQueryItem(QStringLiteral("roomId"), mRoomId); 0053 addQueryParameter(queryUrl); 0054 url.setQuery(queryUrl); 0055 QNetworkRequest request(url); 0056 addAuthRawHeader(request); 0057 addRequestAttribute(request, false); 0058 0059 return request; 0060 } 0061 0062 bool ChannelGetAllUserMentionsJob::requireHttpAuthentication() const 0063 { 0064 return true; 0065 } 0066 0067 void ChannelGetAllUserMentionsJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0068 { 0069 const QJsonObject replyObject = replyJson.object(); 0070 if (replyObject[QLatin1String("success")].toBool()) { 0071 addLoggerInfo(QByteArrayLiteral("ChannelGetAllUserMentionsJob success: ") + replyJson.toJson(QJsonDocument::Indented)); 0072 Q_EMIT channelGetAllUserMentionsDone(replyObject, mRoomId); 0073 } else { 0074 emitFailedMessage(replyErrorString, replyObject); 0075 addLoggerWarning(QByteArrayLiteral("ChannelGetAllUserMentionsJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0076 } 0077 } 0078 0079 QString ChannelGetAllUserMentionsJob::roomId() const 0080 { 0081 return mRoomId; 0082 } 0083 0084 void ChannelGetAllUserMentionsJob::setRoomId(const QString &roomId) 0085 { 0086 mRoomId = roomId; 0087 } 0088 0089 bool ChannelGetAllUserMentionsJob::hasQueryParameterSupport() const 0090 { 0091 return true; 0092 } 0093 0094 #include "moc_channelgetallusermentionsjob.cpp"