2021-05-30 04:09:21 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
2021-07-24 16:16:29 +03:00
|
|
|
#include "CacheStructs.h"
|
|
|
|
|
2021-05-30 04:09:21 +03:00
|
|
|
class MemberList : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
|
2021-07-19 21:34:04 +03:00
|
|
|
Q_PROPERTY(int memberCount READ memberCount NOTIFY memberCountChanged)
|
2021-05-30 04:09:21 +03:00
|
|
|
Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged)
|
|
|
|
Q_PROPERTY(QString roomId READ roomId NOTIFY roomIdChanged)
|
2021-06-12 01:53:32 +03:00
|
|
|
Q_PROPERTY(int numUsersLoaded READ numUsersLoaded NOTIFY numUsersLoadedChanged)
|
2021-07-19 21:49:57 +03:00
|
|
|
Q_PROPERTY(bool loadingMoreMembers READ loadingMoreMembers NOTIFY loadingMoreMembersChanged)
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Mxid,
|
|
|
|
DisplayName,
|
|
|
|
AvatarUrl,
|
2021-08-14 00:58:26 +03:00
|
|
|
Trustlevel,
|
2021-05-30 04:09:21 +03:00
|
|
|
};
|
2021-07-21 17:08:04 +03:00
|
|
|
MemberList(const QString &room_id, QObject *parent = nullptr);
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
return static_cast<int>(m_memberList.size());
|
|
|
|
}
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
QString roomName() const { return QString::fromStdString(info_.name); }
|
2021-07-19 21:34:04 +03:00
|
|
|
int memberCount() const { return info_.member_count; }
|
2021-05-30 04:09:21 +03:00
|
|
|
QString avatarUrl() const { return QString::fromStdString(info_.avatar_url); }
|
|
|
|
QString roomId() const { return room_id_; }
|
2021-06-12 01:53:32 +03:00
|
|
|
int numUsersLoaded() const { return numUsersLoaded_; }
|
2021-07-19 21:49:57 +03:00
|
|
|
bool loadingMoreMembers() const { return loadingMoreMembers_; }
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void roomNameChanged();
|
|
|
|
void memberCountChanged();
|
|
|
|
void avatarUrlChanged();
|
|
|
|
void roomIdChanged();
|
2021-06-12 01:53:32 +03:00
|
|
|
void numUsersLoadedChanged();
|
2021-07-19 21:49:57 +03:00
|
|
|
void loadingMoreMembersChanged();
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void addUsers(const std::vector<RoomMember> &users);
|
|
|
|
|
|
|
|
protected:
|
2021-07-17 22:52:10 +03:00
|
|
|
bool canFetchMore(const QModelIndex &) const override;
|
|
|
|
void fetchMore(const QModelIndex &) override;
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
QVector<QPair<RoomMember, QString>> m_memberList;
|
|
|
|
QString room_id_;
|
|
|
|
RoomInfo info_;
|
2021-07-18 01:24:04 +03:00
|
|
|
int numUsersLoaded_{0};
|
2021-07-19 21:49:57 +03:00
|
|
|
bool loadingMoreMembers_{false};
|
2021-05-30 04:09:21 +03:00
|
|
|
};
|