matrixion/src/InviteesModel.h

75 lines
1.6 KiB
C
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
2021-07-17 20:31:38 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-06-11 03:13:12 +03:00
#ifndef INVITEESMODEL_H
#define INVITEESMODEL_H
#include <QAbstractListModel>
#include <QVector>
class TimelineModel;
2022-10-10 15:38:29 +03:00
class Invitee final : public QObject
2021-06-11 03:13:12 +03:00
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
2021-06-11 03:13:12 +03:00
public:
Invitee(QString mxid,
QString displayName = "",
QString avatarUrl = "",
QObject *parent = nullptr);
2021-06-11 03:13:12 +03:00
signals:
2021-09-18 01:22:33 +03:00
void userInfoLoaded();
2021-06-11 03:13:12 +03:00
private:
2021-09-18 01:22:33 +03:00
const QString mxid_;
QString displayName_;
QString avatarUrl_;
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
friend class InviteesModel;
2021-06-11 03:13:12 +03:00
};
2022-10-10 15:38:29 +03:00
class InviteesModel final : public QAbstractListModel
2021-06-11 03:13:12 +03:00
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(TimelineModel * room READ room CONSTANT)
2021-06-11 03:13:12 +03:00
public:
2021-09-18 01:22:33 +03:00
enum Roles
{
Mxid,
DisplayName,
AvatarUrl,
};
2021-06-11 03:13:12 +03:00
InviteesModel(TimelineModel *room, QObject *parent = nullptr);
TimelineModel *room() const { return room_; }
2021-06-11 03:13:12 +03:00
Q_INVOKABLE void addUser(QString mxid, QString displayName = "", QString avatarUrl = "");
Q_INVOKABLE void removeUser(QString mxid);
2021-06-11 03:13:12 +03:00
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] int rowCount(const QModelIndex & = QModelIndex()) const override
2021-09-18 01:22:33 +03:00
{
return (int)invitees_.size();
}
[[nodiscard]] QVariant
data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
2021-09-18 01:22:33 +03:00
QStringList mxids();
2021-06-11 03:13:12 +03:00
signals:
2021-09-18 01:22:33 +03:00
void accept();
void countChanged();
2021-06-11 03:13:12 +03:00
private:
2021-09-18 01:22:33 +03:00
QVector<Invitee *> invitees_;
TimelineModel *room_;
2021-06-11 03:13:12 +03:00
};
#endif // INVITEESMODEL_H