Show mod and admin in user list.
This commit is contained in:
@@ -235,6 +235,31 @@ Drawer {
|
|||||||
|
|
||||||
text: name
|
text: name
|
||||||
color: MPalette.foreground
|
color: MPalette.foreground
|
||||||
|
textFormat: Text.PlainText
|
||||||
|
elide: Text.ElideRight
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialIcon {
|
||||||
|
Layout.preferredWidth: height
|
||||||
|
Layout.fillHeight: true
|
||||||
|
|
||||||
|
enabled: perm != UserType.Member
|
||||||
|
|
||||||
|
icon: {
|
||||||
|
if (perm == UserType.Admin) {
|
||||||
|
return "\ue853"
|
||||||
|
}
|
||||||
|
if (perm == UserType.Moderator) {
|
||||||
|
return "\ue8e8"
|
||||||
|
}
|
||||||
|
if (perm == UserType.Muted) {
|
||||||
|
return "\ue92a"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
color: MPalette.lighter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ int main(int argc, char* argv[]) {
|
|||||||
qmlRegisterUncreatableType<RoomMessageEvent>("Spectral", 0, 1,
|
qmlRegisterUncreatableType<RoomMessageEvent>("Spectral", 0, 1,
|
||||||
"RoomMessageEvent", "ENUM");
|
"RoomMessageEvent", "ENUM");
|
||||||
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
|
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
|
||||||
|
qmlRegisterUncreatableType<UserType>("Spectral", 0, 1, "UserType", "ENUM");
|
||||||
|
|
||||||
qRegisterMetaType<User*>("User*");
|
qRegisterMetaType<User*>("User*");
|
||||||
qRegisterMetaType<User*>("const User*");
|
qRegisterMetaType<User*>("const User*");
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <room.h>
|
#include <room.h>
|
||||||
#include <user.h>
|
#include <user.h>
|
||||||
|
|
||||||
|
#include "events/roompowerlevelsevent.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtGui/QPixmap>
|
#include <QtGui/QPixmap>
|
||||||
@@ -63,7 +65,7 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
|
|||||||
if (index.row() >= m_users.count()) {
|
if (index.row() >= m_users.count()) {
|
||||||
qDebug()
|
qDebug()
|
||||||
<< "UserListModel, something's wrong: index.row() >= m_users.count()";
|
<< "UserListModel, something's wrong: index.row() >= m_users.count()";
|
||||||
return QVariant();
|
return {};
|
||||||
}
|
}
|
||||||
auto user = m_users.at(index.row());
|
auto user = m_users.at(index.row());
|
||||||
if (role == NameRole) {
|
if (role == NameRole) {
|
||||||
@@ -78,8 +80,38 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
|
|||||||
if (role == ObjectRole) {
|
if (role == ObjectRole) {
|
||||||
return QVariant::fromValue(user);
|
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 {
|
int UserListModel::rowCount(const QModelIndex& parent) const {
|
||||||
@@ -138,6 +170,7 @@ QHash<int, QByteArray> UserListModel::roleNames() const {
|
|||||||
roles[UserIDRole] = "userId";
|
roles[UserIDRole] = "userId";
|
||||||
roles[AvatarRole] = "avatar";
|
roles[AvatarRole] = "avatar";
|
||||||
roles[ObjectRole] = "user";
|
roles[ObjectRole] = "user";
|
||||||
|
roles[PermRole] = "perm";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,19 @@ class Room;
|
|||||||
class User;
|
class User;
|
||||||
} // namespace Quotient
|
} // namespace Quotient
|
||||||
|
|
||||||
|
class UserType : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Types {
|
||||||
|
Admin = 1,
|
||||||
|
Moderator,
|
||||||
|
Member,
|
||||||
|
Muted,
|
||||||
|
};
|
||||||
|
Q_ENUMS(Types)
|
||||||
|
};
|
||||||
|
|
||||||
class UserListModel : public QAbstractListModel {
|
class UserListModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
@@ -21,16 +34,15 @@ class UserListModel : public QAbstractListModel {
|
|||||||
NameRole = Qt::UserRole + 1,
|
NameRole = Qt::UserRole + 1,
|
||||||
UserIDRole,
|
UserIDRole,
|
||||||
AvatarRole,
|
AvatarRole,
|
||||||
ObjectRole
|
ObjectRole,
|
||||||
|
PermRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
using User = Quotient::User;
|
|
||||||
|
|
||||||
UserListModel(QObject* parent = nullptr);
|
UserListModel(QObject* parent = nullptr);
|
||||||
|
|
||||||
Quotient::Room* room() const { return m_currentRoom; }
|
Quotient::Room* room() const { return m_currentRoom; }
|
||||||
void setRoom(Quotient::Room* room);
|
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;
|
QVariant data(const QModelIndex& index, int role = NameRole) const override;
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
@@ -41,16 +53,16 @@ class UserListModel : public QAbstractListModel {
|
|||||||
void roomChanged();
|
void roomChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void userAdded(User* user);
|
void userAdded(Quotient::User* user);
|
||||||
void userRemoved(User* user);
|
void userRemoved(Quotient::User* user);
|
||||||
void refresh(User* user, QVector<int> roles = {});
|
void refresh(Quotient::User* user, QVector<int> roles = {});
|
||||||
void avatarChanged(User* user, const Quotient::Room* context);
|
void avatarChanged(Quotient::User* user, const Quotient::Room* context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Quotient::Room* m_currentRoom;
|
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;
|
int findUserPos(const QString& username) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user