Fix power selector not showing up in user info when some power levels fields are missing (#8297)

pull/21833/head
Michael Telatynski 2022-04-15 12:26:07 +01:00 committed by GitHub
parent d5887bf075
commit 77b0addbc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 13 deletions

View File

@ -921,14 +921,9 @@ function useRoomPermissions(cli: MatrixClient, room: Room, user: RoomMember): IR
canEdit: false, canEdit: false,
canInvite: false, canInvite: false,
}); });
const updateRoomPermissions = useCallback(() => {
if (!room) {
return;
}
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", ""); const updateRoomPermissions = useCallback(() => {
if (!powerLevelEvent) return; const powerLevels = room?.currentState.getStateEvents(EventType.RoomPowerLevels, "")?.getContent();
const powerLevels = powerLevelEvent.getContent();
if (!powerLevels) return; if (!powerLevels) return;
const me = room.getMember(cli.getUserId()); const me = room.getMember(cli.getUserId());
@ -940,17 +935,14 @@ function useRoomPermissions(cli: MatrixClient, room: Room, user: RoomMember): IR
let modifyLevelMax = -1; let modifyLevelMax = -1;
if (canAffectUser) { if (canAffectUser) {
const editPowerLevel = ( const editPowerLevel = powerLevels.events?.[EventType.RoomPowerLevels] ?? powerLevels.state_default ?? 50;
(powerLevels.events ? powerLevels.events["m.room.power_levels"] : null) || if (me.powerLevel >= editPowerLevel) {
powerLevels.state_default
);
if (me.powerLevel >= editPowerLevel && (isMe || me.powerLevel > them.powerLevel)) {
modifyLevelMax = me.powerLevel; modifyLevelMax = me.powerLevel;
} }
} }
setRoomPermissions({ setRoomPermissions({
canInvite: me.powerLevel >= powerLevels.invite, canInvite: me.powerLevel >= (powerLevels.invite ?? 50),
canEdit: modifyLevelMax >= 0, canEdit: modifyLevelMax >= 0,
modifyLevelMax, modifyLevelMax,
}); });