1 /* 2 SPDX-FileCopyrightText: 2019-2021 Laurent Montel <montel@kde.org> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #include "userspresencejob.h" 8 #include "restapimethod.h" 9 #include "rocketchatqtrestapi_debug.h" 10 #include <QJsonDocument> 11 #include <QJsonObject> 12 #include <QNetworkReply> 13 using namespace RocketChatRestApi; UsersPresenceJob(QObject * parent)14UsersPresenceJob::UsersPresenceJob(QObject *parent) 15 : RestApiAbstractJob(parent) 16 { 17 } 18 19 UsersPresenceJob::~UsersPresenceJob() = default; 20 requireHttpAuthentication() const21bool UsersPresenceJob::requireHttpAuthentication() const 22 { 23 return true; 24 } 25 start()26bool UsersPresenceJob::start() 27 { 28 if (!canStart()) { 29 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start userspresence job"; 30 deleteLater(); 31 return false; 32 } 33 submitGetRequest(); 34 addStartRestApiInfo(QByteArrayLiteral("UsersPresenceJob: Ask info about me")); 35 return true; 36 } 37 onGetRequestResponse(const QJsonDocument & replyJson)38void UsersPresenceJob::onGetRequestResponse(const QJsonDocument &replyJson) 39 { 40 const QJsonObject replyObject = replyJson.object(); 41 if (replyObject[QStringLiteral("success")].toBool()) { 42 addLoggerInfo(QByteArrayLiteral("UsersPresenceJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 43 Q_EMIT usersPresenceDone(replyObject); 44 } else { 45 emitFailedMessage(replyObject); 46 addLoggerWarning(QByteArrayLiteral("UsersPresenceJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 47 } 48 } 49 request() const50QNetworkRequest UsersPresenceJob::request() const 51 { 52 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::UsersPresence); 53 54 QNetworkRequest request(url); 55 addAuthRawHeader(request); 56 addRequestAttribute(request, false); 57 58 return request; 59 } 60 canStart() const61bool UsersPresenceJob::canStart() const 62 { 63 if (!RestApiAbstractJob::canStart()) { 64 return false; 65 } 66 return true; 67 } 68