Show mod and admin in user list.
This commit is contained in:
@@ -53,6 +53,7 @@ int main(int argc, char* argv[]) {
|
||||
qmlRegisterUncreatableType<RoomMessageEvent>("Spectral", 0, 1,
|
||||
"RoomMessageEvent", "ENUM");
|
||||
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
|
||||
qmlRegisterUncreatableType<UserType>("Spectral", 0, 1, "UserType", "ENUM");
|
||||
|
||||
qRegisterMetaType<User*>("User*");
|
||||
qRegisterMetaType<User*>("const User*");
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <room.h>
|
||||
#include <user.h>
|
||||
|
||||
#include "events/roompowerlevelsevent.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QPixmap>
|
||||
@@ -63,7 +65,7 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
|
||||
if (index.row() >= m_users.count()) {
|
||||
qDebug()
|
||||
<< "UserListModel, something's wrong: index.row() >= m_users.count()";
|
||||
return QVariant();
|
||||
return {};
|
||||
}
|
||||
auto user = m_users.at(index.row());
|
||||
if (role == NameRole) {
|
||||
@@ -78,8 +80,38 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
|
||||
if (role == ObjectRole) {
|
||||
return QVariant::fromValue(user);
|
||||
}
|
||||
if (role == PermRole) {
|
||||
auto pl = m_currentRoom->getCurrentState<RoomPowerLevelsEvent>();
|
||||
auto userPl = pl->powerLevelForUser(user->id());
|
||||
|
||||
return QVariant();
|
||||
if (userPl == pl->content().usersDefault) {
|
||||
return UserType::Member;
|
||||
}
|
||||
|
||||
if (userPl < pl->content().usersDefault) {
|
||||
return UserType::Muted;
|
||||
}
|
||||
|
||||
auto userPls = pl->users();
|
||||
|
||||
int highestPl = pl->usersDefault();
|
||||
QHash<QString, int>::const_iterator i = userPls.constBegin();
|
||||
while (i != userPls.constEnd()) {
|
||||
if (i.value() > highestPl) {
|
||||
highestPl = i.value();
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
if (userPl == highestPl) {
|
||||
return UserType::Admin;
|
||||
}
|
||||
|
||||
return UserType::Moderator;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
int UserListModel::rowCount(const QModelIndex& parent) const {
|
||||
@@ -138,6 +170,7 @@ QHash<int, QByteArray> UserListModel::roleNames() const {
|
||||
roles[UserIDRole] = "userId";
|
||||
roles[AvatarRole] = "avatar";
|
||||
roles[ObjectRole] = "user";
|
||||
roles[PermRole] = "perm";
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,19 @@ class Room;
|
||||
class User;
|
||||
} // namespace Quotient
|
||||
|
||||
class UserType : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Types {
|
||||
Admin = 1,
|
||||
Moderator,
|
||||
Member,
|
||||
Muted,
|
||||
};
|
||||
Q_ENUMS(Types)
|
||||
};
|
||||
|
||||
class UserListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(
|
||||
@@ -21,16 +34,15 @@ class UserListModel : public QAbstractListModel {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
UserIDRole,
|
||||
AvatarRole,
|
||||
ObjectRole
|
||||
ObjectRole,
|
||||
PermRole,
|
||||
};
|
||||
|
||||
using User = Quotient::User;
|
||||
|
||||
UserListModel(QObject* parent = nullptr);
|
||||
|
||||
Quotient::Room* room() const { return m_currentRoom; }
|
||||
void setRoom(Quotient::Room* room);
|
||||
User* userAt(QModelIndex index) const;
|
||||
Quotient::User* userAt(QModelIndex index) const;
|
||||
|
||||
QVariant data(const QModelIndex& index, int role = NameRole) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
@@ -41,16 +53,16 @@ class UserListModel : public QAbstractListModel {
|
||||
void roomChanged();
|
||||
|
||||
private slots:
|
||||
void userAdded(User* user);
|
||||
void userRemoved(User* user);
|
||||
void refresh(User* user, QVector<int> roles = {});
|
||||
void avatarChanged(User* user, const Quotient::Room* context);
|
||||
void userAdded(Quotient::User* user);
|
||||
void userRemoved(Quotient::User* user);
|
||||
void refresh(Quotient::User* user, QVector<int> roles = {});
|
||||
void avatarChanged(Quotient::User* user, const Quotient::Room* context);
|
||||
|
||||
private:
|
||||
Quotient::Room* m_currentRoom;
|
||||
QList<User*> m_users;
|
||||
QList<Quotient::User*> m_users;
|
||||
|
||||
int findUserPos(User* user) const;
|
||||
int findUserPos(Quotient::User* user) const;
|
||||
int findUserPos(const QString& username) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user