// SPDX-FileCopyrightText: 2021 kaniini // SPDX-FileCopyrightText: 2021 Carl Schwan // SPDX-License-Identifier: GPL-3.0-only #pragma once #include "account/abstractaccount.h" #include "account/relationship.h" #include class AccountConfig; class Account : public AbstractAccount { Q_OBJECT public: explicit Account(const QString &instance_uri, QNetworkAccessManager *nam, bool ignoreSslErrors = false, bool admin = true, QObject *parent = nullptr); explicit Account(AccountConfig *settings, QNetworkAccessManager *nam, QObject *parent = nullptr); ~Account() override; void get(const QUrl &url, bool authenticated, QObject *parent, std::function callback, std::function errorCallback = nullptr) override; void post(const QUrl &url, const QJsonDocument &doc, bool authenticated, QObject *parent, std::function callback, std::function errorCallback, QHash headers = {}) override; void post(const QUrl &url, const QUrlQuery &formdata, bool authenticated, QObject *parent, std::function callback, std::function errorCallback) override; QNetworkReply *post(const QUrl &url, QHttpMultiPart *message, bool authenticated, QObject *parent, std::function callback) override; void put(const QUrl &url, const QJsonDocument &doc, bool authenticated, QObject *parent, std::function callback) override; void put(const QUrl &url, const QUrlQuery &formdata, bool authenticated, QObject *parent, std::function callback) override; void patch(const QUrl &url, QHttpMultiPart *multiPart, bool authenticated, QObject *parent, std::function) override; void deleteResource(const QUrl &url, bool authenticated, QObject *parent, std::function callback) override; QNetworkReply *upload(const QUrl &filename, std::function callback) override; void requestRemoteObject(const QUrl &url, QObject *parent, std::function callback) override; QWebSocket *streamingSocket(const QString &stream); QNetworkAccessManager *qnam() { return m_qnam; } void writeToSettings() override; void buildFromSettings() override; void validateToken(bool newAccount = false) override; Q_INVOKABLE void checkForFollowRequests() override; Q_INVOKABLE void updatePushNotifications() override; Q_INVOKABLE void registerTokodon(bool authCode); private: void unsubscribePushNotifications(); void subscribePushNotifications(); QUrlQuery buildNotificationFormData(); bool m_ignoreSslErrors = false; QNetworkAccessManager *m_qnam; QMap m_websockets; bool m_hasPushSubscription = false; bool m_requestingAdmin = false; // common parts for all HTTP request [[nodiscard]] QNetworkRequest makeRequest(const QUrl &url, bool authenticated) const; void handleReply(QNetworkReply *reply, std::function reply_cb, std::function errorCallback = nullptr) const; };