From 77b0addbc79f629bfd1fb5ac1b6732938db4525c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 15 Apr 2022 12:26:07 +0100 Subject: [PATCH] Fix power selector not showing up in user info when some power levels fields are missing (#8297) --- src/components/views/right_panel/UserInfo.tsx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index 934f88b0a7..93ab84e902 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -921,14 +921,9 @@ function useRoomPermissions(cli: MatrixClient, room: Room, user: RoomMember): IR canEdit: false, canInvite: false, }); - const updateRoomPermissions = useCallback(() => { - if (!room) { - return; - } - const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", ""); - if (!powerLevelEvent) return; - const powerLevels = powerLevelEvent.getContent(); + const updateRoomPermissions = useCallback(() => { + const powerLevels = room?.currentState.getStateEvents(EventType.RoomPowerLevels, "")?.getContent(); if (!powerLevels) return; const me = room.getMember(cli.getUserId()); @@ -940,17 +935,14 @@ function useRoomPermissions(cli: MatrixClient, room: Room, user: RoomMember): IR let modifyLevelMax = -1; if (canAffectUser) { - const editPowerLevel = ( - (powerLevels.events ? powerLevels.events["m.room.power_levels"] : null) || - powerLevels.state_default - ); - if (me.powerLevel >= editPowerLevel && (isMe || me.powerLevel > them.powerLevel)) { + const editPowerLevel = powerLevels.events?.[EventType.RoomPowerLevels] ?? powerLevels.state_default ?? 50; + if (me.powerLevel >= editPowerLevel) { modifyLevelMax = me.powerLevel; } } setRoomPermissions({ - canInvite: me.powerLevel >= powerLevels.invite, + canInvite: me.powerLevel >= (powerLevels.invite ?? 50), canEdit: modifyLevelMax >= 0, modifyLevelMax, });