diff --git a/imports/Spectral/Panel/RoomDrawer.qml b/imports/Spectral/Panel/RoomDrawer.qml index 48561703e..27714d779 100644 --- a/imports/Spectral/Panel/RoomDrawer.qml +++ b/imports/Spectral/Panel/RoomDrawer.qml @@ -235,6 +235,31 @@ Drawer { text: name 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 } } diff --git a/src/main.cpp b/src/main.cpp index babe5d8d0..c4a89ccc7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,7 @@ int main(int argc, char* argv[]) { qmlRegisterUncreatableType("Spectral", 0, 1, "RoomMessageEvent", "ENUM"); qmlRegisterUncreatableType("Spectral", 0, 1, "RoomType", "ENUM"); + qmlRegisterUncreatableType("Spectral", 0, 1, "UserType", "ENUM"); qRegisterMetaType("User*"); qRegisterMetaType("const User*"); diff --git a/src/userlistmodel.cpp b/src/userlistmodel.cpp index 6ab23ce93..dffa64ac2 100644 --- a/src/userlistmodel.cpp +++ b/src/userlistmodel.cpp @@ -4,6 +4,8 @@ #include #include +#include "events/roompowerlevelsevent.h" + #include #include #include @@ -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(); + 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::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 UserListModel::roleNames() const { roles[UserIDRole] = "userId"; roles[AvatarRole] = "avatar"; roles[ObjectRole] = "user"; + roles[PermRole] = "perm"; return roles; } diff --git a/src/userlistmodel.h b/src/userlistmodel.h index 0e83d37b1..b3d617e35 100644 --- a/src/userlistmodel.h +++ b/src/userlistmodel.h @@ -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 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 roles = {}); + void avatarChanged(Quotient::User* user, const Quotient::Room* context); private: Quotient::Room* m_currentRoom; - QList m_users; + QList m_users; - int findUserPos(User* user) const; + int findUserPos(Quotient::User* user) const; int findUserPos(const QString& username) const; };