Warn when you attempt to leave room that you are the only member of

Signed-off-by: Aaron Raimist <aaron@raim.ist>
This commit is contained in:
Aaron Raimist 2020-11-10 15:04:01 -06:00
parent 46e01196f0
commit 29a81bbe85
No known key found for this signature in database
GPG key ID: 37419210002890EF
2 changed files with 17 additions and 1 deletions

View file

@ -1056,8 +1056,21 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private leaveRoomWarnings(roomId: string) { private leaveRoomWarnings(roomId: string) {
const roomToLeave = MatrixClientPeg.get().getRoom(roomId); const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
// Show a warning if there are additional complications. // Show a warning if there are additional complications.
const joinRules = roomToLeave.currentState.getStateEvents('m.room.join_rules', '');
const warnings = []; const warnings = [];
const memberCount = roomToLeave.currentState.getJoinedMemberCount();
if (memberCount === 1) {
warnings.push(
<span className="warning" key="only_member_warning">
{' '/* Whitespace, otherwise the sentences get smashed together */ }
{ _t("You are the only member of this room. This room will become unjoinable if you leave.") }
</span>
);
return warnings;
}
const joinRules = roomToLeave.currentState.getStateEvents('m.room.join_rules', '');
if (joinRules) { if (joinRules) {
const rule = joinRules.getContent().join_rule; const rule = joinRules.getContent().join_rule;
if (rule !== "public") { if (rule !== "public") {
@ -1076,6 +1089,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
const roomToLeave = MatrixClientPeg.get().getRoom(roomId); const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
const warnings = this.leaveRoomWarnings(roomId); const warnings = this.leaveRoomWarnings(roomId);
const hasWarnings = warnings.length > 0;
Modal.createTrackedDialog('Leave room', '', QuestionDialog, { Modal.createTrackedDialog('Leave room', '', QuestionDialog, {
title: _t("Leave room"), title: _t("Leave room"),
@ -1086,6 +1100,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
</span> </span>
), ),
button: _t("Leave"), button: _t("Leave"),
danger: hasWarnings,
onFinished: (shouldLeave) => { onFinished: (shouldLeave) => {
if (shouldLeave) { if (shouldLeave) {
const d = leaveRoomBehaviour(roomId); const d = leaveRoomBehaviour(roomId);

View file

@ -2317,6 +2317,7 @@
"Cannot create rooms in this community": "Cannot create rooms in this community", "Cannot create rooms in this community": "Cannot create rooms in this community",
"You do not have permission to create rooms in this community.": "You do not have permission to create rooms in this community.", "You do not have permission to create rooms in this community.": "You do not have permission to create rooms in this community.",
"This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.", "This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.",
"You are the only member of this room. This room will become unjoinable if you leave.": "You are the only member of this room. This room will become unjoinable if you leave.",
"Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?", "Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?",
"Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s",
"Signed Out": "Signed Out", "Signed Out": "Signed Out",