2021-05-30 04:09:21 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2023-01-02 06:25:33 +03:00
|
|
|
// SPDX-FileCopyrightText: 2023 Nheko Contributors
|
2021-05-30 04:09:21 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2022-04-23 02:59:40 +03:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
#include <mtx/events/power_levels.hpp>
|
2021-05-30 04:09:21 +03:00
|
|
|
|
2021-07-24 16:16:29 +03:00
|
|
|
#include "CacheStructs.h"
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class MemberListBackend final : public QAbstractListModel
|
2021-05-30 04:09:21 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2021-05-30 04:09:21 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
|
|
|
|
Q_PROPERTY(int memberCount READ memberCount NOTIFY memberCountChanged)
|
|
|
|
Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged)
|
|
|
|
Q_PROPERTY(QString roomId READ roomId NOTIFY roomIdChanged)
|
|
|
|
Q_PROPERTY(int numUsersLoaded READ numUsersLoaded NOTIFY numUsersLoadedChanged)
|
|
|
|
Q_PROPERTY(bool loadingMoreMembers READ loadingMoreMembers NOTIFY loadingMoreMembersChanged)
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Mxid,
|
|
|
|
DisplayName,
|
|
|
|
AvatarUrl,
|
|
|
|
Trustlevel,
|
2022-04-23 02:59:40 +03:00
|
|
|
Powerlevel,
|
2021-09-18 01:22:33 +03:00
|
|
|
};
|
2022-04-23 02:59:40 +03:00
|
|
|
|
|
|
|
MemberListBackend(const QString &room_id, QObject *parent = nullptr);
|
2021-05-30 04:09:21 +03:00
|
|
|
|
2021-09-18 01:22:33 +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;
|
2021-05-30 04:09:21 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QString roomName() const { return QString::fromStdString(info_.name); }
|
2022-10-01 20:05:44 +03:00
|
|
|
int memberCount() const { return (int)info_.member_count; }
|
2021-09-18 01:22:33 +03:00
|
|
|
QString avatarUrl() const { return QString::fromStdString(info_.avatar_url); }
|
|
|
|
QString roomId() const { return room_id_; }
|
|
|
|
int numUsersLoaded() const { return numUsersLoaded_; }
|
|
|
|
bool loadingMoreMembers() const { return loadingMoreMembers_; }
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
signals:
|
2021-09-18 01:22:33 +03:00
|
|
|
void roomNameChanged();
|
|
|
|
void memberCountChanged();
|
|
|
|
void avatarUrlChanged();
|
|
|
|
void roomIdChanged();
|
|
|
|
void numUsersLoadedChanged();
|
|
|
|
void loadingMoreMembersChanged();
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
public slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void addUsers(const std::vector<RoomMember> &users);
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
protected:
|
2021-09-18 01:22:33 +03:00
|
|
|
bool canFetchMore(const QModelIndex &) const override;
|
|
|
|
void fetchMore(const QModelIndex &) override;
|
2021-05-30 04:09:21 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QVector<QPair<RoomMember, QString>> m_memberList;
|
|
|
|
QString room_id_;
|
|
|
|
RoomInfo info_;
|
|
|
|
int numUsersLoaded_{0};
|
|
|
|
bool loadingMoreMembers_{false};
|
2022-04-23 02:59:40 +03:00
|
|
|
|
|
|
|
mtx::events::state::PowerLevels powerLevels_;
|
|
|
|
|
|
|
|
friend class MemberList;
|
|
|
|
};
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class MemberList final : public QSortFilterProxyModel
|
2022-04-23 02:59:40 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
|
|
|
|
Q_PROPERTY(int memberCount READ memberCount NOTIFY memberCountChanged)
|
|
|
|
Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged)
|
|
|
|
Q_PROPERTY(QString roomId READ roomId NOTIFY roomIdChanged)
|
|
|
|
Q_PROPERTY(int numUsersLoaded READ numUsersLoaded NOTIFY numUsersLoadedChanged)
|
|
|
|
Q_PROPERTY(bool loadingMoreMembers READ loadingMoreMembers NOTIFY loadingMoreMembersChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum MemberSortRoles
|
|
|
|
{
|
|
|
|
Mxid = MemberListBackend::Roles::Mxid,
|
|
|
|
DisplayName = MemberListBackend::Roles::DisplayName,
|
|
|
|
Powerlevel = MemberListBackend::Roles::Powerlevel,
|
|
|
|
};
|
|
|
|
Q_ENUM(MemberSortRoles)
|
|
|
|
|
|
|
|
MemberList(const QString &room_id, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
QString roomName() const { return m_model.roomName(); }
|
|
|
|
int memberCount() const { return m_model.memberCount(); }
|
|
|
|
QString avatarUrl() const { return m_model.avatarUrl(); }
|
|
|
|
QString roomId() const { return m_model.roomId(); }
|
|
|
|
int numUsersLoaded() const { return m_model.numUsersLoaded(); }
|
|
|
|
bool loadingMoreMembers() const { return m_model.loadingMoreMembers(); }
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void roomNameChanged();
|
|
|
|
void memberCountChanged();
|
|
|
|
void avatarUrlChanged();
|
|
|
|
void roomIdChanged();
|
|
|
|
void numUsersLoadedChanged();
|
|
|
|
void loadingMoreMembersChanged();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setFilterString(const QString &text);
|
|
|
|
void sortBy(const MemberSortRoles role);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
|
|
|
|
|
|
|
private:
|
2022-04-23 15:53:36 +03:00
|
|
|
QString filterString;
|
2022-04-23 02:59:40 +03:00
|
|
|
MemberListBackend m_model;
|
2021-05-30 04:09:21 +03:00
|
|
|
};
|