File indexing completed on 2024-12-22 04:45:28
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 "getusernamesuggestionjob.h" 0008 #include "restapimethod.h" 0009 #include <QJsonDocument> 0010 #include <QJsonObject> 0011 #include <QNetworkReply> 0012 using namespace RocketChatRestApi; 0013 GetUsernameSuggestionJob::GetUsernameSuggestionJob(QObject *parent) 0014 : RestApiAbstractJob(parent) 0015 { 0016 } 0017 0018 GetUsernameSuggestionJob::~GetUsernameSuggestionJob() = default; 0019 0020 bool GetUsernameSuggestionJob::canStart() const 0021 { 0022 if (!RestApiAbstractJob::canStart()) { 0023 return false; 0024 } 0025 return true; 0026 } 0027 0028 bool GetUsernameSuggestionJob::start() 0029 { 0030 if (!canStart()) { 0031 deleteLater(); 0032 return false; 0033 } 0034 submitGetRequest(); 0035 addStartRestApiInfo("GetUsernameSuggestionJob start"); 0036 return true; 0037 } 0038 0039 void GetUsernameSuggestionJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0040 { 0041 const QJsonObject replyObject = replyJson.object(); 0042 if (replyObject[QLatin1String("success")].toBool()) { 0043 addLoggerInfo(QByteArrayLiteral("GetUsernameSuggestionJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0044 const QString result = replyObject[QLatin1String("result")].toString(); 0045 Q_EMIT getUsernameSuggestionDone(result); 0046 } else { 0047 emitFailedMessage(replyErrorString, replyObject); 0048 addLoggerWarning(QByteArrayLiteral("GetUsernameSuggestionJob problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0049 } 0050 } 0051 0052 QNetworkRequest GetUsernameSuggestionJob::request() const 0053 { 0054 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::UsersGetUsernameSuggestion); 0055 QNetworkRequest request(url); 0056 addAuthRawHeader(request); 0057 return request; 0058 } 0059 0060 bool GetUsernameSuggestionJob::requireHttpAuthentication() const 0061 { 0062 return true; 0063 } 0064 0065 #include "moc_getusernamesuggestionjob.cpp"