summary refs log tree commit diff
path: root/src/InviteesModel.h
blob: 64e013b167c4d7aee0cce5596480055d879c9c49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QAbstractListModel>
#include <QQmlEngine>
#include <QVector>

class TimelineModel;

class Invitee final : public QObject
{
    Q_OBJECT

public:
    Invitee(QString mxid,
            QString displayName = "",
            QString avatarUrl   = "",
            QObject *parent     = nullptr);

signals:
    void userInfoLoaded();

private:
    const QString mxid_;
    QString displayName_;
    QString avatarUrl_;

    friend class InviteesModel;
};

class InviteesModel final : public QAbstractListModel
{
    Q_OBJECT
    QML_ELEMENT
    QML_UNCREATABLE("")

    Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
    Q_PROPERTY(TimelineModel *room READ room CONSTANT)

public:
    enum Roles
    {
        Mxid,
        DisplayName,
        AvatarUrl,
    };

    InviteesModel(TimelineModel *room, QObject *parent = nullptr);

    TimelineModel *room() const { return room_; }

    Q_INVOKABLE void addUser(QString mxid, QString displayName = "", QString avatarUrl = "");
    Q_INVOKABLE void removeUser(QString mxid);

    [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
    [[nodiscard]] int rowCount(const QModelIndex & = QModelIndex()) const override
    {
        return (int)invitees_.size();
    }
    [[nodiscard]] QVariant
    data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QStringList mxids();

signals:
    void accept();
    void countChanged();

private:
    QVector<Invitee *> invitees_;
    TimelineModel *room_;
};