diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index f8be6327bf..66b689ddb9 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -51,7 +51,6 @@ import BaseCard from "./BaseCard"; import {E2EStatus} from "../../../utils/ShieldUtils"; import ImageView from "../elements/ImageView"; import Spinner from "../elements/Spinner"; -import IconButton from "../elements/IconButton"; import PowerSelector from "../elements/PowerSelector"; import MemberAvatar from "../avatars/MemberAvatar"; import PresenceLabel from "../rooms/PresenceLabel"; @@ -1028,24 +1027,15 @@ const PowerLevelSection: React.FC<{ roomPermissions: IRoomPermissions; powerLevels: IPowerLevelsContent; }> = ({user, room, roomPermissions, powerLevels}) => { - const [isEditing, setEditing] = useState(false); - if (isEditing) { - return ( setEditing(false)} />); + if (roomPermissions.canEdit) { + return (); } else { const powerLevelUsersDefault = powerLevels.users_default || 0; const powerLevel = parseInt(user.powerLevel, 10); - const modifyButton = roomPermissions.canEdit ? - ( setEditing(true)} />) : null; const role = textualPowerLevel(powerLevel, powerLevelUsersDefault); - const label = _t("%(role)s in %(roomName)s", - {role, roomName: room.name}, - {strong: label => {label}}, - ); return (
-
{label}{modifyButton}
+
{role}
); } @@ -1055,20 +1045,15 @@ const PowerLevelEditor: React.FC<{ user: User; room: Room; roomPermissions: IRoomPermissions; - onFinished(): void; -}> = ({user, room, roomPermissions, onFinished}) => { +}> = ({user, room, roomPermissions}) => { const cli = useContext(MatrixClientContext); - const [isUpdating, setIsUpdating] = useState(false); const [selectedPowerLevel, setSelectedPowerLevel] = useState(parseInt(user.powerLevel, 10)); - const [isDirty, setIsDirty] = useState(false); - const onPowerChange = useCallback((powerLevel) => { - setIsDirty(true); - setSelectedPowerLevel(parseInt(powerLevel, 10)); - }, [setSelectedPowerLevel, setIsDirty]); + const onPowerChange = useCallback(async (powerLevelStr: string) => { + const powerLevel = parseInt(powerLevelStr, 10); + setSelectedPowerLevel(powerLevel); - const changePowerLevel = useCallback(async () => { - const _applyPowerChange = (roomId, target, powerLevel, powerLevelEvent) => { + const applyPowerChange = (roomId, target, powerLevel, powerLevelEvent) => { return cli.setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).then( function() { // NO-OP; rely on the m.room.member event coming down else we could @@ -1084,64 +1069,42 @@ const PowerLevelEditor: React.FC<{ ); }; - try { - if (!isDirty) { - return; - } + const roomId = user.roomId; + const target = user.userId; - setIsUpdating(true); + const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", ""); + if (!powerLevelEvent) return; - const powerLevel = selectedPowerLevel; + const myUserId = cli.getUserId(); + const myPower = powerLevelEvent.getContent().users[myUserId]; + if (myPower && parseInt(myPower) === powerLevel) { + const {finished} = Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, { + title: _t("Warning!"), + description: +
+ { _t("You will not be able to undo this change as you are promoting the user " + + "to have the same power level as yourself.") }
+ { _t("Are you sure?") } +
, + button: _t("Continue"), + }); - const roomId = user.roomId; - const target = user.userId; - - const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", ""); - if (!powerLevelEvent) return; - - if (!powerLevelEvent.getContent().users) { - _applyPowerChange(roomId, target, powerLevel, powerLevelEvent); - return; - } - - const myUserId = cli.getUserId(); + const [confirmed] = await finished; + if (!confirmed) return; + } else if (myUserId === target) { // If we are changing our own PL it can only ever be decreasing, which we cannot reverse. - if (myUserId === target) { - try { - if (!(await warnSelfDemote())) return; - } catch (e) { - console.error("Failed to warn about self demotion: ", e); - } - await _applyPowerChange(roomId, target, powerLevel, powerLevelEvent); - return; + try { + if (!(await warnSelfDemote())) return; + } catch (e) { + console.error("Failed to warn about self demotion: ", e); } - - const myPower = powerLevelEvent.getContent().users[myUserId]; - if (parseInt(myPower) === powerLevel) { - const {finished} = Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, { - title: _t("Warning!"), - description: -
- { _t("You will not be able to undo this change as you are promoting the user " + - "to have the same power level as yourself.") }
- { _t("Are you sure?") } -
, - button: _t("Continue"), - }); - - const [confirmed] = await finished; - if (!confirmed) return; - } - await _applyPowerChange(roomId, target, powerLevel, powerLevelEvent); - } finally { - onFinished(); } - }, [user.roomId, user.userId, cli, selectedPowerLevel, isDirty, setIsUpdating, onFinished, room]); + + await applyPowerChange(roomId, target, powerLevel, powerLevelEvent); + }, [user.roomId, user.userId, cli, room]); const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", ""); const powerLevelUsersDefault = powerLevelEvent ? powerLevelEvent.getContent().users_default : 0; - const buttonOrSpinner = isUpdating ? : - ; return (
@@ -1151,9 +1114,7 @@ const PowerLevelEditor: React.FC<{ maxValue={roomPermissions.modifyLevelMax} usersDefault={powerLevelUsersDefault} onChange={onPowerChange} - disabled={isUpdating} /> - {buttonOrSpinner}
); }; @@ -1343,13 +1304,17 @@ const BasicUserInfo: React.FC<{ } let memberDetails; - if (room && member.roomId) { - memberDetails = ; + // hide the Roles section for DMs as it doesn't make sense there + if (room && member.roomId && !DMRoomMap.shared().getUserIdForRoomId(member.roomId)) { + memberDetails =
+

{ _t("Role") }

+ +
; } // only display the devices list if our client supports E2E @@ -1419,12 +1384,7 @@ const BasicUserInfo: React.FC<{ ); return - { memberDetails && -
-
- { memberDetails } -
-
} + { memberDetails } { securitySection } %(role)s in %(roomName)s": "%(role)s in %(roomName)s", "Failed to change power level": "Failed to change power level", "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.": "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.", "Are you sure?": "Are you sure?", @@ -1597,6 +1596,7 @@ "Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?": "Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?", "Deactivate user": "Deactivate user", "Failed to deactivate user": "Failed to deactivate user", + "Role": "Role", "This client does not support end-to-end encryption.": "This client does not support end-to-end encryption.", "Security": "Security", "The session you are trying to verify doesn't support scanning a QR code or emoji verification, which is what %(brand)s supports. Try with a different client.": "The session you are trying to verify doesn't support scanning a QR code or emoji verification, which is what %(brand)s supports. Try with a different client.",