File indexing completed on 2024-09-15 07:24:25
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #include "account/abstractaccount.h" 0005 0006 class MockAccount : public AbstractAccount 0007 { 0008 Q_OBJECT 0009 0010 public: 0011 explicit MockAccount(QObject *parent = nullptr); 0012 void get(const QUrl &url, 0013 bool authenticated, 0014 QObject *parent, 0015 std::function<void(QNetworkReply *)> callback, 0016 std::function<void(QNetworkReply *)> errorCallback = nullptr) override; 0017 0018 void post(const QUrl &url, 0019 const QJsonDocument &doc, 0020 bool authenticated, 0021 QObject *parent, 0022 std::function<void(QNetworkReply *)> callback, 0023 std::function<void(QNetworkReply *)> errorCallback, 0024 QHash<QByteArray, QByteArray> headers = {}) override; 0025 0026 void post(const QUrl &url, 0027 const QUrlQuery &formdata, 0028 bool authenticated, 0029 QObject *parent, 0030 std::function<void(QNetworkReply *)> callback, 0031 std::function<void(QNetworkReply *)> errorCallback = nullptr) override; 0032 0033 QNetworkReply *post(const QUrl &url, QHttpMultiPart *message, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0034 0035 void put(const QUrl &url, const QJsonDocument &doc, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0036 void put(const QUrl &url, const QUrlQuery &doc, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0037 0038 QNetworkReply *upload(const QUrl &filename, std::function<void(QNetworkReply *)> callback) override; 0039 0040 void patch(const QUrl &url, QHttpMultiPart *multiPart, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)>) override; 0041 0042 void deleteResource(const QUrl &url, bool authenticated, QObject *parent, std::function<void(QNetworkReply *)> callback) override; 0043 0044 void writeToSettings() override; 0045 0046 void buildFromSettings() override; 0047 0048 void validateToken(bool newAccount = false) override; 0049 0050 bool hasFollowRequests() const override; 0051 0052 void checkForFollowRequests() override; 0053 0054 void registerPost(const QString &url, QNetworkReply *reply); 0055 0056 void registerGet(const QUrl &url, QNetworkReply *reply); 0057 0058 void setFakeIdentity(const QJsonObject &object); 0059 void clearFakeIdentity(); 0060 0061 void updatePushNotifications() override {}; 0062 0063 Q_INVOKABLE void mentionNotification(); 0064 Q_INVOKABLE void favoriteNotification(); 0065 Q_INVOKABLE void boostNotification(); 0066 Q_INVOKABLE void followNotification(); 0067 Q_INVOKABLE void followRequestNotification(); 0068 Q_INVOKABLE void statusNotification(); 0069 Q_INVOKABLE void updateNotification(); 0070 Q_INVOKABLE void pollNotification(); 0071 0072 private: 0073 void readNotificationFromFile(QLatin1String filename); 0074 0075 QHash<QUrl, QNetworkReply *> m_postReplies; 0076 QHash<QUrl, QNetworkReply *> m_getReplies; 0077 };