File indexing completed on 2024-05-12 05:04:14

0001 // SPDX-FileCopyrightText: 2021 kaniini <https://git.pleroma.social/kaniini>
0002 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 #pragma once
0006 
0007 #include "abstracttimelinemodel.h"
0008 
0009 /// Model for the notifications page
0010 /// \see AbstractTimelineModel
0011 class NotificationModel : public AbstractTimelineModel
0012 {
0013     Q_OBJECT
0014     QML_ELEMENT
0015 
0016     Q_PROPERTY(QStringList excludeTypes READ excludeTypes WRITE setExcludesTypes NOTIFY excludeTypesChanged)
0017 
0018 public:
0019     explicit NotificationModel(QObject *parent = nullptr);
0020 
0021     int rowCount(const QModelIndex &parent) const override;
0022     QVariant data(const QModelIndex &index, int role) const override;
0023 
0024     virtual void fillTimeline(const QUrl &next = {});
0025 
0026     /// Get a shared pointer to the underlying notification object at \p index
0027     std::shared_ptr<Notification> internalData(const QModelIndex &index) const;
0028 
0029     /// Returns the list of excluded notification types
0030     /// \see setExcludesTypes
0031     QStringList excludeTypes() const;
0032 
0033     /// Set the types of notifications to exclude
0034     /// Valid options are "mention", "status", "reblog", "follow", "follow_request", "favourite", "poll" and "update"
0035     /// \see excludeTypes
0036     void setExcludesTypes(const QStringList &excludeTypes);
0037 
0038 public Q_SLOTS:
0039     /// Reply to the notification at \p index
0040     /// \see wantReply
0041     void actionReply(const QModelIndex &index);
0042 
0043     /// Favorite the notification at \p index
0044     void actionFavorite(const QModelIndex &index);
0045 
0046     /// Boost the notification at \p index
0047     void actionRepeat(const QModelIndex &index);
0048 
0049     /// Delete and re-draft the notification at \p index
0050     /// \see postSourceReady
0051     void actionRedraft(const QModelIndex &index, bool isEdit);
0052 
0053     /// Delete the notification at \p index
0054     void actionDelete(const QModelIndex &index);
0055 
0056     /// Bookmark the notification at \p index
0057     void actionBookmark(const QModelIndex &index);
0058 Q_SIGNALS:
0059     /// Emitted when the list of excluded notification types change
0060     /// \see setExcludesTypes
0061     void excludeTypesChanged();
0062 
0063     /// Emitted when actionReply is called
0064     void wantReply(AbstractAccount *account, Post *post, const QModelIndex &index);
0065 
0066 protected:
0067     void fetchMore(const QModelIndex &parent) override;
0068     bool canFetchMore(const QModelIndex &parent) const override;
0069 
0070     QString m_timelineName;
0071     AccountManager *m_manager = nullptr;
0072 
0073     QList<std::shared_ptr<Notification>> m_notifications;
0074     QStringList m_excludeTypes;
0075     QUrl m_next;
0076 };