File indexing completed on 2025-02-23 04:35:15
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 "comment.h" 0007 0008 #include <abstractapi.h> 0009 0010 #include <QAbstractListModel> 0011 #include <QDateTime> 0012 #include <QFutureWatcher> 0013 #include <QUrl> 0014 #include <QtQml> 0015 0016 class CommentsModel : public QAbstractListModel 0017 { 0018 Q_OBJECT 0019 QML_ELEMENT 0020 0021 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0022 0023 public: 0024 enum CustomRoles { AuthorRole = Qt::UserRole, AuthorAvatarRole, ContentRole }; 0025 0026 explicit CommentsModel(QObject *parent = nullptr); 0027 0028 bool loading() const; 0029 void setLoading(bool loading); 0030 0031 QVariant data(const QModelIndex &index, int role) const override; 0032 int rowCount(const QModelIndex &parent) const override; 0033 QHash<int, QByteArray> roleNames() const override; 0034 0035 Q_INVOKABLE void fillComments(const QString &videoId); 0036 Q_INVOKABLE void loadMore(); 0037 0038 Q_SIGNALS: 0039 void loadingChanged(); 0040 0041 private: 0042 void fill(); 0043 0044 QFutureWatcher<QInvidious::CommentsResult> *m_futureWatcher = nullptr; 0045 QList<QInvidious::Comment> m_comments; 0046 bool m_loading = false; 0047 QString m_continuation; 0048 QString m_videoId; 0049 };