Fix showing permissions settings for v12 rooms

This commit is contained in:
Tobias Fella
2025-09-08 08:14:17 +00:00
parent d67cb89505
commit 0fd924be7b
4 changed files with 17 additions and 5 deletions

View File

@@ -93,6 +93,9 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(memberId); return QVariant::fromValue(memberId);
} }
if (role == PowerLevelRole) { if (role == PowerLevelRole) {
if (m_currentRoom->isCreator(memberId)) {
return std::numeric_limits<int>::max();
}
auto plEvent = m_currentRoom->currentState().get<RoomPowerLevelsEvent>(); auto plEvent = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
if (!plEvent) { if (!plEvent) {
return 0; return 0;
@@ -118,6 +121,9 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
PowerLevel::nameForLevel(PowerLevel::levelForValue(userPl)), PowerLevel::nameForLevel(PowerLevel::levelForValue(userPl)),
userPl); userPl);
} }
if (role == IsCreatorRole) {
return m_currentRoom->isCreator(memberId);
}
return {}; return {};
} }
@@ -219,6 +225,7 @@ QHash<int, QByteArray> UserListModel::roleNames() const
roles[ObjectRole] = "user"; roles[ObjectRole] = "user";
roles[PowerLevelRole] = "powerLevel"; roles[PowerLevelRole] = "powerLevel";
roles[PowerLevelStringRole] = "powerLevelString"; roles[PowerLevelStringRole] = "powerLevelString";
roles[IsCreatorRole] = "isCreator";
return roles; return roles;
} }

View File

@@ -48,6 +48,7 @@ public:
ObjectRole, /**< The QObject for the user. */ ObjectRole, /**< The QObject for the user. */
PowerLevelRole, /**< The user's power level in the current room. */ PowerLevelRole, /**< The user's power level in the current room. */
PowerLevelStringRole, /**< The name of the user's power level in the current room. */ PowerLevelStringRole, /**< The name of the user's power level in the current room. */
IsCreatorRole, /**< Whether this user is considered a creator of the current room. */
}; };
Q_ENUM(EventRoles) Q_ENUM(EventRoles)

View File

@@ -605,7 +605,7 @@ public:
* *
* For unusual room versions, this information might be wrong. * For unusual room versions, this information might be wrong.
*/ */
bool roomCreatorHasUltimatePowerLevel() const; Q_INVOKABLE bool roomCreatorHasUltimatePowerLevel() const;
/** /**
* @brief Whether this user is considered a creator of this room. Only applies to post-v12 rooms. * @brief Whether this user is considered a creator of this room. Only applies to post-v12 rooms.

View File

@@ -22,6 +22,8 @@ FormCard.FormCardPage {
title: i18nc('@title:window', 'Permissions') title: i18nc('@title:window', 'Permissions')
readonly property bool loading: permissions.count === 0 && !root.room.roomCreatorHasUltimatePowerLevel()
readonly property PowerLevelModel powerLevelModel: PowerLevelModel { readonly property PowerLevelModel powerLevelModel: PowerLevelModel {
showMute: false showMute: false
} }
@@ -32,10 +34,11 @@ FormCard.FormCardPage {
FormCard.FormHeader { FormCard.FormHeader {
title: i18nc("@title", "Privileged Users") title: i18nc("@title", "Privileged Users")
visible: permissions.count > 0 visible: !root.loading
} }
FormCard.FormCard { FormCard.FormCard {
visible: permissions.count > 0 visible: !root.loading
Repeater { Repeater {
id: permissions id: permissions
model: KSortFilterProxyModel { model: KSortFilterProxyModel {
@@ -53,6 +56,7 @@ FormCard.FormCardPage {
required property string name required property string name
required property int powerLevel required property int powerLevel
required property string powerLevelString required property string powerLevelString
required property bool isCreator
text: name text: name
textItem.textFormat: Text.PlainText textItem.textFormat: Text.PlainText
@@ -62,7 +66,7 @@ FormCard.FormCardPage {
QQC2.Label { QQC2.Label {
id: powerLevelLabel id: powerLevelLabel
text: privilegedUserDelegate.powerLevelString text: privilegedUserDelegate.powerLevelString
visible: !root.room.canSendState("m.room.power_levels") || (root.room.memberEffectivePowerLevel(root.room.localMember.id) <= privilegedUserDelegate.powerLevel && privilegedUserDelegate.userId != root.room.localMember.id) visible: (!root.room.canSendState("m.room.power_levels") || (root.room.memberEffectivePowerLevel(root.room.localMember.id) <= privilegedUserDelegate.powerLevel && privilegedUserDelegate.userId != root.room.localMember.id)) || privilegedUserDelegate.isCreator
color: Kirigami.Theme.disabledTextColor color: Kirigami.Theme.disabledTextColor
} }
QQC2.ComboBox { QQC2.ComboBox {
@@ -400,7 +404,7 @@ FormCard.FormCardPage {
} }
Item { Item {
visible: permissions.count === 0 visible: root.loading
Layout.fillWidth: true Layout.fillWidth: true
implicitHeight: root.height * 0.9 implicitHeight: root.height * 0.9
Kirigami.LoadingPlaceholder { Kirigami.LoadingPlaceholder {