File indexing completed on 2024-12-01 04:35:42

0001 /*
0002    SPDX-FileCopyrightText: 2017-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 "user.h"
0011 #include <QAbstractListModel>
0012 #include <QVector>
0013 class UsersModel;
0014 class LIBRUQOLACORE_EXPORT UsersForRoomModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 public:
0018     enum UsersForRoomRoles {
0019         UserName = Qt::UserRole + 1,
0020         UserId,
0021         Name,
0022         IconStatus,
0023         DisplayName,
0024         Status,
0025     };
0026     Q_ENUM(UsersForRoomRoles)
0027 
0028     explicit UsersForRoomModel(QObject *parent = nullptr);
0029     ~UsersForRoomModel() override;
0030 
0031     void setUsers(const QVector<User> &users);
0032 
0033     void clear();
0034     int rowCount(const QModelIndex &parent = {}) const override;
0035     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0036 
0037     void parseUsersForRooms(const QJsonObject &root, UsersModel *model, bool restapi);
0038     void setUserStatusChanged(const User &newuser);
0039 
0040     [[nodiscard]] int total() const;
0041     void setTotal(int total);
0042 
0043     [[nodiscard]] int offset() const;
0044     void setOffset(int offset);
0045 
0046     [[nodiscard]] bool hasFullList() const;
0047     void setHasFullList(bool hasFullList);
0048     [[nodiscard]] int usersCount() const;
0049 
0050     void setLoadMoreUsersInProgress(bool inProgress);
0051     [[nodiscard]] bool loadMoreUsersInProgress() const;
0052 Q_SIGNALS:
0053     void hasFullListChanged();
0054     void userStatusChanged(const QString &userId);
0055     void loadingInProgressChanged();
0056 
0057 private:
0058     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT QString generateDisplayName(const User &user) const;
0059     LIBRUQOLACORE_NO_EXPORT void checkFullList();
0060     QVector<User> mUsers;
0061     int mTotal = 0;
0062     int mOffset = 0;
0063     bool mHasFullList = false;
0064     bool mLoadingInProgress = false;
0065 };