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

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 "accountmanager.h"
0007 
0008 class AbstractAccount;
0009 class PostEditorBackend;
0010 
0011 /// Base class for most timeline classes such as the home and notification timelines
0012 /// \see TimelineModel
0013 /// \see NotificationTimeline
0014 class AbstractTimelineModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 
0018     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0019 
0020 public:
0021     enum CustoRoles {
0022         IdRole = Qt::UserRole + 1, ///< Post id
0023         OriginalIdRole, ///< Original post id (boosted posts generate their own id and live in IdRole)
0024         UrlRole, ///< Original URL of the post, can be from a different instance
0025         ContentRole, ///< Content text of the post
0026         SpoilerTextRole, ///< Spoiler label for the post
0027         AuthorIdentityRole, ///< Identity of the author
0028         PublishedAtRole, ///< Date that the post was published at
0029         RelativeTimeRole, ///< Human-readable and locale-aware relative time of the original post date
0030         AbsoluteTimeRole, ///< Human-readable and locale-aware absolute time of the original post date
0031         SensitiveRole, ///< Whether or not the post is marked as sensitive
0032         VisibilityRole, ///< The visibility of the post
0033         WasEditedRole, ///< If the post was edited at all
0034         EditedAtRole, ///< The datetime of the last edit
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         IsGroupRole,
0067         IsInGroupRole,
0068         NumInGroupRole,
0069 
0070         SelectedRole, ///< Used in ThreadModel. Is this post the selected (or root) post?
0071         FiltersRole, ///< The filters that may have hidden this post
0072 
0073         PostRole, ///< The original Post object
0074 
0075         ExtraRole, ///< Base role for sub-class roles
0076     };
0077 
0078     explicit AbstractTimelineModel(QObject *parent = nullptr);
0079 
0080     QHash<int, QByteArray> roleNames() const override;
0081 
0082     /// Return if the timeline is still loading
0083     /// \see setLoading
0084     bool loading() const;
0085 
0086     /// Set the loading status of the timeline
0087     /// \see loading
0088     /// \see loadingChanged
0089     void setLoading(bool loading);
0090 
0091     /// Favorite the \p post at \p index
0092     void actionFavorite(const QModelIndex &index, Post *post);
0093 
0094     /// Boost the \p post at \p index
0095     void actionRepeat(const QModelIndex &index, Post *post);
0096 
0097     /// Delete and re-draft the \p post at \p index
0098     /// \see postSourceReady
0099     void actionRedraft(const QModelIndex &index, Post *post, bool isEdit);
0100 
0101     /// Delete the \p post at \p index
0102     /// May have no effect if the account does not have permission to delete the post
0103     void actionDelete(const QModelIndex &index, Post *post);
0104 
0105     /// Bookmark the \p post at \p index
0106     void actionBookmark(const QModelIndex &index, Post *post);
0107 
0108     /// Pin the \p post at \p index
0109     void actionPin(const QModelIndex &index, Post *post);
0110 Q_SIGNALS:
0111     /// Emitted when the timeline loading status has changed
0112     void loadingChanged();
0113 
0114     /// Emitted when a redraft is requested and the original post source has been fetched
0115     /// \see actionRedraft
0116     void postSourceReady(PostEditorBackend *backend, bool isEdit);
0117 
0118 protected:
0119     QVariant postData(Post *post, int role) const;
0120 
0121     AbstractAccount *m_account = nullptr;
0122     bool m_loading = false;
0123 };