File indexing completed on 2024-05-26 08:52:35

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqolacore_export.h"
0010 #include <QAbstractListModel>
0011 class Discussions;
0012 class LIBRUQOLACORE_EXPORT DiscussionsModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015 public:
0016     enum DiscussionRoles {
0017         ParentId = Qt::UserRole + 1,
0018         Description,
0019         NumberOfMessages,
0020         LastMessage,
0021         DiscussionRoomId,
0022         TimeStamp,
0023         SortByTimeStamp,
0024         UserName,
0025     };
0026     Q_ENUM(DiscussionRoles)
0027 
0028     explicit DiscussionsModel(QObject *parent = nullptr);
0029     ~DiscussionsModel() override;
0030 
0031     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0032     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0033 
0034     void setDiscussions(const Discussions &discussions);
0035 
0036     void initialize();
0037 
0038     [[nodiscard]] QString roomId() const;
0039     void setRoomId(const QString &roomId);
0040 
0041     void parseDiscussions(const QJsonObject &discussionsObj, const QString &roomId);
0042 
0043     void addMoreDiscussions(const QJsonObject &discussionsObj);
0044     Discussions *discussions() const;
0045     [[nodiscard]] int total() const;
0046 
0047     void setHasFullList(bool state);
0048     [[nodiscard]] bool hasFullList() const;
0049 
0050     [[nodiscard]] bool loadMoreDiscussionsInProgress() const;
0051     void setLoadMoreDiscussionsInProgress(bool loadMoreDiscussionsInProgress);
0052 
0053     void clear();
0054 
0055 Q_SIGNALS:
0056     void hasFullListChanged();
0057     void totalChanged();
0058     void loadingInProgressChanged();
0059 
0060 private:
0061     LIBRUQOLACORE_NO_EXPORT void checkFullList();
0062     QString mRoomId;
0063     bool mLoadMoreDiscussionsInProgress = false;
0064     bool mHasFullList = false;
0065     Discussions *const mDiscussions;
0066 };