File indexing completed on 2024-12-22 04:45:26
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 "roomsautocompleteavailableforteamsjob.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 RoomsAutocompleteAvailableForTeamsJob::RoomsAutocompleteAvailableForTeamsJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 RoomsAutocompleteAvailableForTeamsJob::~RoomsAutocompleteAvailableForTeamsJob() = default; 0021 0022 bool RoomsAutocompleteAvailableForTeamsJob::requireHttpAuthentication() const 0023 { 0024 return true; 0025 } 0026 0027 bool RoomsAutocompleteAvailableForTeamsJob::start() 0028 { 0029 if (!canStart()) { 0030 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start RoomsAutocompleteAvailableForTeamsJob job"; 0031 deleteLater(); 0032 return false; 0033 } 0034 submitGetRequest(); 0035 0036 addStartRestApiInfo(QByteArrayLiteral("RoomsAutocompleteAvailableForTeamsJob: Ask all rooms")); 0037 return true; 0038 } 0039 0040 void RoomsAutocompleteAvailableForTeamsJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0041 { 0042 const QJsonObject replyObject = replyJson.object(); 0043 if (replyObject[QLatin1String("success")].toBool()) { 0044 addLoggerInfo(QByteArrayLiteral("RoomsAutocompleteAvailableForTeamsJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 Q_EMIT roomsAutoCompleteChannelAndPrivateDone(replyObject); 0046 } else { 0047 emitFailedMessage(replyErrorString, replyObject); 0048 addLoggerWarning(QByteArrayLiteral("RoomsAutocompleteAvailableForTeamsJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0049 } 0050 } 0051 0052 QNetworkRequest RoomsAutocompleteAvailableForTeamsJob::request() const 0053 { 0054 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::RoomsAutocompleteAvailableForTeams); 0055 QUrlQuery queryUrl; 0056 queryUrl.addQueryItem(QStringLiteral("name"), mRoomsAutocompleteInfo.name); 0057 url.setQuery(queryUrl); 0058 QNetworkRequest request(url); 0059 addAuthRawHeader(request); 0060 addRequestAttribute(request); 0061 return request; 0062 } 0063 0064 RoomsAutocompleteAvailableForTeamsJob::RoomsAutocompleteChannelAndPrivateInfo RoomsAutocompleteAvailableForTeamsJob::roomsCompleterInfo() const 0065 { 0066 return mRoomsAutocompleteInfo; 0067 } 0068 0069 void RoomsAutocompleteAvailableForTeamsJob::setRoomsCompleterInfo( 0070 const RoomsAutocompleteAvailableForTeamsJob::RoomsAutocompleteChannelAndPrivateInfo &roomCompleterInfo) 0071 { 0072 mRoomsAutocompleteInfo = roomCompleterInfo; 0073 } 0074 0075 bool RoomsAutocompleteAvailableForTeamsJob::RoomsAutocompleteChannelAndPrivateInfo::isValid() const 0076 { 0077 return !name.isEmpty(); 0078 } 0079 0080 #include "moc_roomsautocompleteavailableforteamsjob.cpp"