diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index d775059c319..5184553d1c6 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1198,6 +1198,35 @@ export default class MatrixChat extends React.PureComponent { ); } } + + const client = MatrixClientPeg.get(); + if (client && roomToLeave) { + const plEvent = roomToLeave.currentState.getStateEvents(EventType.RoomPowerLevels, ""); + const plContent = plEvent ? plEvent.getContent() : {}; + const userLevels = plContent.users || {}; + const currentUserLevel = userLevels[client.getUserId()!]; + const userLevelValues = Object.values(userLevels); + if (userLevelValues.every((x) => typeof x === "number")) { + const maxUserLevel = Math.max(...(userLevelValues as number[])); + // If the user is the only user with highest power level + if ( + maxUserLevel === currentUserLevel && + userLevelValues.lastIndexOf(maxUserLevel) == userLevelValues.indexOf(maxUserLevel) + ) { + const warning = + maxUserLevel >= 100 + ? _t("leave_room_dialog|room_leave_admin_warning") + : _t("leave_room_dialog|room_leave_mod_warning"); + warnings.push( + + {" " /* Whitespace, otherwise the sentences get smashed together */} + {warning} + , + ); + } + } + } + return warnings; } @@ -1222,6 +1251,7 @@ export default class MatrixChat extends React.PureComponent { ), button: _t("action|leave"), + danger: warnings.length > 0, onFinished: async (shouldLeave) => { if (shouldLeave) { await leaveRoomBehaviour(cli, roomId); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d1e9acb3ba8..31ff6cf91dc 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1515,6 +1515,8 @@ "last_person_warning": "You are the only person here. If you leave, no one will be able to join in the future, including you.", "leave_room_question": "Are you sure you want to leave the room '%(roomName)s'?", "leave_space_question": "Are you sure you want to leave the space '%(spaceName)s'?", + "room_leave_admin_warning": "You're the only administrator in this room. If you leave, nobody will be able to change room settings or take other important actions.", + "room_leave_mod_warning": "You're the only moderator in this room. If you leave, nobody will be able to change room settings or take other important actions.", "room_rejoin_warning": "This room is not public. You will not be able to rejoin without an invite.", "space_rejoin_warning": "This space is not public. You will not be able to rejoin without an invite." },