diff options
Diffstat (limited to 'buteo-plugins/buteo-sync-plugin-fediverse-notifications/fediversenotificationssyncadaptor.h')
| -rw-r--r-- | buteo-plugins/buteo-sync-plugin-fediverse-notifications/fediversenotificationssyncadaptor.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/buteo-plugins/buteo-sync-plugin-fediverse-notifications/fediversenotificationssyncadaptor.h b/buteo-plugins/buteo-sync-plugin-fediverse-notifications/fediversenotificationssyncadaptor.h new file mode 100644 index 0000000..24f2745 --- /dev/null +++ b/buteo-plugins/buteo-sync-plugin-fediverse-notifications/fediversenotificationssyncadaptor.h @@ -0,0 +1,104 @@ +/**************************************************************************** + ** + ** Copyright (C) 2013-2026 Jolla Ltd. + ** + ** This program/library is free software; you can redistribute it and/or + ** modify it under the terms of the GNU Lesser General Public License + ** version 2.1 as published by the Free Software Foundation. + ** + ** This program/library is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this program/library; if not, write to the Free + ** Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + ** 02110-1301 USA + ** + ****************************************************************************/ + +#ifndef FEDIVERSENOTIFICATIONSSYNCADAPTOR_H +#define FEDIVERSENOTIFICATIONSSYNCADAPTOR_H + +#include "fediversedatatypesyncadaptor.h" + +#include <QtCore/QDateTime> +#include <QtCore/QHash> +#include <QtCore/QSet> +#include <QtNetwork/QNetworkReply> + +class Notification; + +class FediverseNotificationsSyncAdaptor : public FediverseNotificationsDataTypeSyncAdaptor +{ + Q_OBJECT + +public: + FediverseNotificationsSyncAdaptor(QObject *parent); + ~FediverseNotificationsSyncAdaptor(); + + QString syncServiceName() const override; + +protected: + QString authServiceName() const override; + void purgeDataForOldAccount(int oldId, SocialNetworkSyncAdaptor::PurgeMode mode) override; + void beginSync(int accountId, const QString &accessToken) override; + void finalize(int accountId) override; + +private: + struct PendingNotification { + QString notificationId; + QString summary; + QString body; + QString link; + QDateTime timestamp; + }; + + struct PendingSyncState { + QString accessToken; + bool markerKnown = false; + QString unreadFloorId; + QString lastFetchedId; + QString maxFetchedId; + QSet<QString> unreadNotificationIds; + QHash<QString, PendingNotification> pendingNotifications; + }; + + static QString sanitizeContent(const QString &content); + static QDateTime parseTimestamp(const QString ×tampString); + static int compareNotificationIds(const QString &left, const QString &right); + QString loadLastFetchedId(int accountId) const; + void saveLastFetchedId(int accountId, const QString &lastFetchedId); + + void requestUnreadMarker(int accountId, const QString &accessToken); + void requestNotifications(int accountId, + const QString &accessToken, + const QString &minId, + const QString &maxId = QString()); + void requestMarkRead(int accountId, const QString &accessToken, const QString &lastReadId); + void publishSystemNotification(int accountId, const PendingNotification ¬ificationData); + Notification *createNotification(int accountId, const QString ¬ificationId); + Notification *findNotification(int accountId, const QString ¬ificationId); + void closeAccountNotifications(int accountId, const QSet<QString> &keepNotificationIds = QSet<QString>()); + static QString notificationObjectKey(int accountId, const QString ¬ificationId); + void maybeMarkAccountNotificationsRead(int accountId, + const QString &accessToken, + Notification *ignoredNotification = 0); + void markReadFromNotification(Notification *notification); + void removeCachedNotification(Notification *notification); + +private Q_SLOTS: + void finishedUnreadMarkerHandler(); + void finishedNotificationsHandler(); + void finishedMarkReadHandler(); + void notificationClosedWithReason(uint reason); + +private: + QHash<int, QString> m_accessTokens; + QHash<int, PendingSyncState> m_pendingSyncStates; + QHash<int, QString> m_lastMarkedReadIds; + QHash<QString, Notification *> m_notificationObjects; +}; + +#endif // FEDIVERSENOTIFICATIONSSYNCADAPTOR_H |
