File indexing completed on 2024-04-14 04:54:46

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 "libruqola_private_export.h"
0010 #include "user.h"
0011 #include <QAbstractListModel>
0012 class LIBRUQOLACORE_TESTS_EXPORT UsersModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015 public:
0016     enum UserRoles {
0017         UserName = Qt::UserRole + 1,
0018         UserId,
0019         UserStatus,
0020         UserIcon,
0021         UserStatusText,
0022     };
0023     Q_ENUM(UserRoles)
0024 
0025     explicit UsersModel(QObject *parent = nullptr);
0026     ~UsersModel() override;
0027 
0028     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0029     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0030 
0031     void addUser(const User &userFromUserId);
0032     void removeUser(const QString &userId);
0033 
0034     void updateUser(const QJsonObject &array);
0035     [[nodiscard]] QString userStatusIconFileName(const QString &name) const;
0036 
0037     [[nodiscard]] User::PresenceStatus status(const QString &userId) const;
0038     [[nodiscard]] User fullUserInfo(const QString &userName) const;
0039     [[nodiscard]] bool userIsOffline(const QString &name) const;
0040 
0041     [[nodiscard]] QString userStatusStr(const QString &name) const;
0042 Q_SIGNALS:
0043     void userStatusChanged(const User &user);
0044     void userNameChanged(const User &user);
0045     void nameChanged(const User &user);
0046     void statusMessageChanged(const User &user);
0047 
0048 private:
0049     Q_DISABLE_COPY(UsersModel)
0050     QVector<User> mUsers;
0051 };