File indexing completed on 2024-04-28 16:13:16

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 #include <QUrl>
0008 #include <memory>
0009 
0010 class Identity;
0011 
0012 class SocialGraphModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0016     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
0017     Q_PROPERTY(QString displayName READ displayName NOTIFY nameChanged)
0018     Q_PROPERTY(QString placeholderText READ placeholderText NOTIFY nameChanged)
0019     Q_PROPERTY(bool isFollowRequest READ isFollowRequest CONSTANT)
0020     Q_PROPERTY(bool isFollowing READ isFollowing CONSTANT)
0021     Q_PROPERTY(bool isFollower READ isFollower CONSTANT)
0022 
0023     /// The account id of the account we want to display
0024     Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged)
0025 
0026 public:
0027     enum CustomRoles {
0028         IdentityRole = Qt::UserRole + 1,
0029     };
0030 
0031     explicit SocialGraphModel(QObject *parent = nullptr);
0032 
0033     QVariant data(const QModelIndex &index, int role) const override;
0034     int rowCount(const QModelIndex &parent) const override;
0035     QHash<int, QByteArray> roleNames() const override;
0036 
0037     bool loading() const;
0038     void setLoading(bool loading);
0039 
0040     QString name() const;
0041     void setName(const QString &name);
0042     QString displayName() const;
0043     QString placeholderText() const;
0044     QString accountId() const;
0045     void setAccountId(const QString &accountId);
0046     bool isFollowRequest() const;
0047     bool isFollowing() const;
0048     bool isFollower() const;
0049 
0050 public Q_SLOTS:
0051     void actionAllow(const QModelIndex &index);
0052     void actionDeny(const QModelIndex &index);
0053 
0054 Q_SIGNALS:
0055     void loadingChanged();
0056     void nameChanged();
0057     void accountIdChanged();
0058 
0059 protected:
0060     void fetchMore(const QModelIndex &parent) override;
0061     bool canFetchMore(const QModelIndex &parent) const override;
0062 
0063 private:
0064     void fillTimeline();
0065 
0066     QList<std::shared_ptr<Identity>> m_accounts;
0067     bool m_loading = false;
0068     QUrl m_next;
0069 
0070     QString m_followListName;
0071     QString m_accountId;
0072 };