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