Improved user perms.

This commit is contained in:
Black Hat
2020-01-06 01:39:55 +08:00
parent 3544e5441f
commit d13a88a854
3 changed files with 26 additions and 15 deletions

View File

@@ -240,26 +240,28 @@ Drawer {
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
MaterialIcon { Label {
Layout.preferredWidth: height visible: perm != UserType.Member
Layout.fillHeight: true
enabled: perm != UserType.Member text: {
if (perm == UserType.Owner) {
icon: { return "Owner"
}
if (perm == UserType.Admin) { if (perm == UserType.Admin) {
return "\ue853" return "Admin"
} }
if (perm == UserType.Moderator) { if (perm == UserType.Moderator) {
return "\ue8e8" return "Mod"
} }
if (perm == UserType.Muted) { if (perm == UserType.Muted) {
return "\ue92a" return "Muted"
} }
return "" return ""
} }
color: perm == UserType.Muted ? MPalette.lighter : MPalette.accent
color: MPalette.lighter font.pixelSize: 12
textFormat: Text.PlainText
wrapMode: Text.NoWrap
} }
} }

View File

@@ -84,11 +84,11 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
auto pl = m_currentRoom->getCurrentState<RoomPowerLevelsEvent>(); auto pl = m_currentRoom->getCurrentState<RoomPowerLevelsEvent>();
auto userPl = pl->powerLevelForUser(user->id()); auto userPl = pl->powerLevelForUser(user->id());
if (userPl == pl->content().usersDefault) { if (userPl == pl->content().usersDefault) { // Shortcut
return UserType::Member; return UserType::Member;
} }
if (userPl < pl->content().usersDefault) { if (userPl < pl->powerLevelForState("m.room.message")) {
return UserType::Muted; return UserType::Muted;
} }
@@ -105,10 +105,18 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
} }
if (userPl == highestPl) { if (userPl == highestPl) {
return UserType::Owner;
}
if (userPl >= pl->powerLevelForState("m.room.power_levels")) {
return UserType::Admin; return UserType::Admin;
} }
return UserType::Moderator; if (userPl >= pl->ban() || userPl >= pl->kick() || userPl >= pl->redact()) {
return UserType::Moderator;
}
return UserType::Member;
} }
return {}; return {};

View File

@@ -17,7 +17,8 @@ class UserType : public QObject {
public: public:
enum Types { enum Types {
Admin = 1, Owner = 1,
Admin,
Moderator, Moderator,
Member, Member,
Muted, Muted,