Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 03dc48b

Browse files
authored
Merge pull request #9452 from Arnei/last-admin-leave-room-warning
Add leave room warning for last admin
2 parents 56d7911 + 1a1699d commit 03dc48b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/components/structures/MatrixChat.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,35 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11981198
);
11991199
}
12001200
}
1201+
1202+
const client = MatrixClientPeg.get();
1203+
if (client && roomToLeave) {
1204+
const plEvent = roomToLeave.currentState.getStateEvents(EventType.RoomPowerLevels, "");
1205+
const plContent = plEvent ? plEvent.getContent() : {};
1206+
const userLevels = plContent.users || {};
1207+
const currentUserLevel = userLevels[client.getUserId()!];
1208+
const userLevelValues = Object.values(userLevels);
1209+
if (userLevelValues.every((x) => typeof x === "number")) {
1210+
const maxUserLevel = Math.max(...(userLevelValues as number[]));
1211+
// If the user is the only user with highest power level
1212+
if (
1213+
maxUserLevel === currentUserLevel &&
1214+
userLevelValues.lastIndexOf(maxUserLevel) == userLevelValues.indexOf(maxUserLevel)
1215+
) {
1216+
const warning =
1217+
maxUserLevel >= 100
1218+
? _t("leave_room_dialog|room_leave_admin_warning")
1219+
: _t("leave_room_dialog|room_leave_mod_warning");
1220+
warnings.push(
1221+
<strong className="warning" key="last_admin_warning">
1222+
{" " /* Whitespace, otherwise the sentences get smashed together */}
1223+
{warning}
1224+
</strong>,
1225+
);
1226+
}
1227+
}
1228+
}
1229+
12011230
return warnings;
12021231
}
12031232

@@ -1222,6 +1251,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
12221251
</span>
12231252
),
12241253
button: _t("action|leave"),
1254+
danger: warnings.length > 0,
12251255
onFinished: async (shouldLeave) => {
12261256
if (shouldLeave) {
12271257
await leaveRoomBehaviour(cli, roomId);

src/i18n/strings/en_EN.json

+2
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,8 @@
15151515
"last_person_warning": "You are the only person here. If you leave, no one will be able to join in the future, including you.",
15161516
"leave_room_question": "Are you sure you want to leave the room '%(roomName)s'?",
15171517
"leave_space_question": "Are you sure you want to leave the space '%(spaceName)s'?",
1518+
"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.",
1519+
"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.",
15181520
"room_rejoin_warning": "This room is not public. You will not be able to rejoin without an invite.",
15191521
"space_rejoin_warning": "This space is not public. You will not be able to rejoin without an invite."
15201522
},

0 commit comments

Comments
 (0)