File indexing completed on 2024-09-01 14:05:14
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include "account/accountmanager.h" 0007 #include "post.h" 0008 #include <QAbstractListModel> 0009 #include <qabstractitemmodel.h> 0010 0011 class AbstractAccount; 0012 class PostEditorBackend; 0013 0014 /// Base class for most timeline classes such as the home and notification timelines 0015 /// \see TimelineModel 0016 /// \see NotificationTimeline 0017 class AbstractTimelineModel : public QAbstractListModel 0018 { 0019 Q_OBJECT 0020 0021 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0022 public: 0023 enum CustoRoles { 0024 IdRole = Qt::UserRole + 1, ///< Post id 0025 OriginalIdRole, ///< Original post id (boosted posts generate their own id and live in IdRole) 0026 UrlRole, ///< Original URL of the post, can be from a different instance 0027 ContentRole, ///< Content text of the post 0028 SpoilerTextRole, ///< Spoiler label for the post 0029 AuthorIdentityRole, ///< Identity of the author 0030 PublishedAtRole, ///< Date that the post was published at 0031 RelativeTimeRole, ///< Human-readable and locale-aware relative time of the original post date 0032 AbsoluteTimeRole, ///< Human-readable and locale-aware absolute time of the original post date 0033 SensitiveRole, ///< Whether or not the post is marked as sensitive 0034 VisibilityRole, ///< The visibility of the post 0035 0036 // Additional content 0037 AttachmentsRole, ///< Media attachments for the post, which can be null 0038 CardRole, ///< Card for the post, which can be null 0039 ApplicationRole, ///< Application used for publishing the post 0040 PollRole, ///< Poll for the post, which can be null 0041 MentionsRole, ///< List of mentions in the post 0042 0043 // Reblog 0044 IsBoostedRole, ///< Does this post show up because it's boosted? 0045 BoostAuthorIdentityRole, ///< If this is boosted, the identity which boosted it and can be null 0046 0047 // Reply 0048 IsReplyRole, ///< Is this post a reply to someone? 0049 ReplyAuthorIdentityRole, ///< If this is a reply, the identity of the account this post is replying to 0050 0051 // Interaction count 0052 ReblogsCountRole, ///< Number of accounts who boosted this post 0053 RepliesCountRole, ///< Number of accounts who replied to this post 0054 FavouritesCountRole, ///< Number of accounts who favorited this post 0055 0056 // User self interaction 0057 FavouritedRole, ///< Did your own account favorite this post? 0058 RebloggedRole, ///< Has your own account boosted this post? 0059 MutedRole, ///< Has your own account muted this post? 0060 BookmarkedRole, ///< Has your own account bookmarked this post? 0061 PinnedRole, ///< Is this a pinned post on an account? 0062 0063 // Notification 0064 NotificationActorIdentityRole, ///< The identity of account related to this notification 0065 TypeRole, ///< The notification type 0066 0067 SelectedRole, ///< Used in ThreadModel. Is this post the selected (or root) post? 0068 FiltersRole, ///< The filters that may have hidden this post 0069 0070 PostRole, ///< The original Post object 0071 0072 ExtraRole, ///< Base role for sub-class roles 0073 }; 0074 0075 explicit AbstractTimelineModel(QObject *parent = nullptr); 0076 0077 QHash<int, QByteArray> roleNames() const override; 0078 0079 /// Return if the timeline is still loading 0080 /// \see setLoading 0081 bool loading() const; 0082 0083 /// Set the loading status of the timeline 0084 /// \see loading 0085 /// \see loadingChanged 0086 void setLoading(bool loading); 0087 0088 /// Favorite the \p post at \p index 0089 void actionFavorite(const QModelIndex &index, Post *post); 0090 0091 /// Boost the \p post at \p index 0092 void actionRepeat(const QModelIndex &index, Post *post); 0093 0094 /// Delete and re-draft the \p post at \p index 0095 /// \see postSourceReady 0096 void actionRedraft(const QModelIndex &index, Post *post, bool isEdit); 0097 0098 /// Delete the \p post at \p index 0099 /// May have no effect if the account does not have permission to delete the post 0100 void actionDelete(const QModelIndex &index, Post *post); 0101 0102 /// Bookmark the \p post at \p index 0103 void actionBookmark(const QModelIndex &index, Post *post); 0104 0105 /// Pin the \p post at \p index 0106 void actionPin(const QModelIndex &index, Post *post); 0107 Q_SIGNALS: 0108 /// Emitted when the timeline loading status has changed 0109 void loadingChanged(); 0110 0111 /// Emitted when a redraft is requested and the original post source has been fetched 0112 /// \see actionRedraft 0113 void postSourceReady(PostEditorBackend *backend, bool isEdit); 0114 0115 protected: 0116 QVariant postData(Post *post, int role) const; 0117 0118 AbstractAccount *m_account = nullptr; 0119 bool m_loading = false; 0120 };