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 #pragma once
0008 
0009 #include "librocketchatrestapi-qt_export.h"
0010 #include "userbasejob.h"
0011 namespace RocketChatRestApi
0012 {
0013 class LIBROCKETCHATRESTAPI_QT_EXPORT SetAvatarJob : public UserBaseJob
0014 {
0015     Q_OBJECT
0016 public:
0017     struct LIBROCKETCHATRESTAPI_QT_EXPORT SetAvatarInfo {
0018         QString mAvatarUrl;
0019         QUrl mImageUrl;
0020         [[nodiscard]] bool isValid() const;
0021     };
0022 
0023     explicit SetAvatarJob(QObject *parent = nullptr);
0024     ~SetAvatarJob() override;
0025 
0026     [[nodiscard]] bool start() override;
0027     [[nodiscard]] bool requireHttpAuthentication() const override;
0028     [[nodiscard]] bool canStart() const override;
0029     [[nodiscard]] QNetworkRequest request() const override;
0030 
0031     [[nodiscard]] QJsonDocument json() const;
0032 
0033     [[nodiscard]] SetAvatarInfo avatarInfo() const;
0034     void setAvatarInfo(const SetAvatarInfo &avatarInfo);
0035 
0036 Q_SIGNALS:
0037     void setAvatarDone();
0038 
0039 protected:
0040     [[nodiscard]] QString errorMessage(const QString &str, const QJsonObject &details) override;
0041 
0042 private:
0043     Q_DISABLE_COPY(SetAvatarJob)
0044     LIBROCKETCHATRESTAPI_QT_NO_EXPORT void slotSetAvatar();
0045     LIBROCKETCHATRESTAPI_QT_NO_EXPORT void onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) override;
0046     SetAvatarInfo mAvatarInfo;
0047 };
0048 }