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-only
0003 
0004 #pragma once
0005 
0006 #include "timelinemodel.h"
0007 
0008 class AbstractAccount;
0009 
0010 /// TimelineModel to show the last post of an account
0011 ///
0012 /// This expose as well some properties of the user (\see identity)
0013 class AccountModel : public TimelineModel
0014 {
0015     Q_OBJECT
0016     QML_ELEMENT
0017 
0018     /// The account id of the account we want to display
0019     Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged)
0020 
0021     /// The identity of the account
0022     Q_PROPERTY(Identity *identity READ identity NOTIFY identityChanged)
0023 
0024     /// The account of the current user
0025     Q_PROPERTY(AbstractAccount *account READ account NOTIFY accountChanged)
0026 
0027     /// This property holds whether the current user is the account displayed by this model
0028     Q_PROPERTY(bool isSelf READ isSelf NOTIFY identityChanged)
0029 
0030     /// Whether or not to exclude replies
0031     Q_PROPERTY(bool excludeReplies MEMBER m_excludeReplies NOTIFY filtersChanged)
0032 
0033     /// Whether or not to exclude boosts
0034     Q_PROPERTY(bool excludeBoosts MEMBER m_excludeBoosts NOTIFY filtersChanged)
0035 
0036     /// Whether or not to exclude pinned posts
0037     Q_PROPERTY(bool excludePinned MEMBER m_excludePinned NOTIFY filtersChanged)
0038 
0039     /// Only include posts that have a media attachment
0040     Q_PROPERTY(bool onlyMedia MEMBER m_onlyMedia NOTIFY filtersChanged)
0041 
0042     /// Search for posts with a specific hashtag, leave blank to not search for any
0043     Q_PROPERTY(QString tagged MEMBER m_tagged NOTIFY filtersChanged)
0044 
0045     /// The current account tab, is set to None by default to disable filtering.
0046     Q_PROPERTY(AccountTab currentTab MEMBER m_currentTab NOTIFY tabChanged)
0047 
0048 public:
0049     explicit AccountModel(QObject *parent = nullptr);
0050 
0051     enum AccountTab { Posts, Replies, Media, None };
0052     Q_ENUM(AccountTab)
0053 
0054     QString accountId() const;
0055     void setAccountId(const QString &accountId);
0056 
0057     Identity *identity() const;
0058 
0059     QString displayName() const override;
0060     AbstractAccount *account() const;
0061     bool isSelf() const;
0062 
0063     void fillTimeline(const QString &fromId = {}) override;
0064 
0065 Q_SIGNALS:
0066     void identityChanged();
0067     void accountChanged();
0068     void accountIdChanged();
0069     void filtersChanged();
0070     void tabChanged();
0071 
0072 protected:
0073     void reset() override;
0074 
0075 private:
0076     void updateRelationships();
0077     void updateTabFilters();
0078 
0079     std::shared_ptr<Identity> m_identity;
0080     QString m_accountId;
0081 
0082     bool m_excludeReplies = false;
0083     bool m_excludeBoosts = false;
0084     bool m_excludePinned = false;
0085     bool m_onlyMedia = false;
0086     QString m_tagged;
0087     AccountTab m_currentTab = AccountTab::None;
0088 };