From a34a8bb425452a7854df29bf340b8b51b8a47d6e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 22 Mar 2019 17:36:54 -0600 Subject: [PATCH 1/3] Use leaveRoomChain when leaving a room Requires https://github.com/matrix-org/matrix-js-sdk/pull/868 Fixes https://github.com/vector-im/riot-web/issues/8539 We don't need to use leaveRoomChain when rejecting invites because we won't have the references needed. This leaves the couple spots where we do actually leave a room, and use the new function for that. --- src/SlashCommands.js | 2 +- src/components/structures/MatrixChat.js | 41 ++++++++++++++++--------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index 039ccb928f..b5f2ed8ba2 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -431,7 +431,7 @@ export const CommandMap = { if (!targetRoomId) targetRoomId = roomId; return success( - cli.leave(targetRoomId).then(function() { + cli.leaveRoomChain(targetRoomId).then(function() { dis.dispatch({action: 'view_next_room'}); }), ); diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 2622a6bf93..17ce6e0e73 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1058,34 +1058,47 @@ export default React.createClass({ button: _t("Leave"), onFinished: (shouldLeave) => { if (shouldLeave) { - const d = MatrixClientPeg.get().leave(roomId); + const d = MatrixClientPeg.get().leaveRoomChain(roomId); // FIXME: controller shouldn't be loading a view :( const Loader = sdk.getComponent("elements.Spinner"); const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner'); - d.then(() => { + d.then((errors) => { modal.close(); + + if (errors[roomId]) { + // Something went wrong + const err = errors[roomId]; + console.error("Failed to leave room " + roomId + " " + err); + let title = _t("Failed to leave room"); + let message = _t("Server may be unavailable, overloaded, or you hit a bug."); + if (err.errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { + title = _t("Can't leave Server Notices room"); + message = _t( + "This room is used for important messages from the Homeserver, " + + "so you cannot leave it.", + ); + } else if (err && err.message) { + message = err.message; + } + Modal.createTrackedDialog('Failed to leave room', '', ErrorDialog, { + title: title, + description: message, + }); + return; + } + if (this.state.currentRoomId === roomId) { dis.dispatch({action: 'view_next_room'}); } }, (err) => { + // This should only happen if something went seriously wrong with leaving the chain. modal.close(); console.error("Failed to leave room " + roomId + " " + err); - let title = _t("Failed to leave room"); - let message = _t("Server may be unavailable, overloaded, or you hit a bug."); - if (err.errcode == 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { - title = _t("Can't leave Server Notices room"); - message = _t( - "This room is used for important messages from the Homeserver, " + - "so you cannot leave it.", - ); - } else if (err && err.message) { - message = err.message; - } Modal.createTrackedDialog('Failed to leave room', '', ErrorDialog, { title: title, - description: message, + description: _t("Unknown error"), }); }); } From 4fd48988e96683df1dd3c543c700bc1afd0166a2 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 22 Mar 2019 17:39:42 -0600 Subject: [PATCH 2/3] Check for any errors leaving the room, not just the top level --- src/components/structures/MatrixChat.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 17ce6e0e73..26956858be 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1067,10 +1067,11 @@ export default React.createClass({ d.then((errors) => { modal.close(); - if (errors[roomId]) { - // Something went wrong - const err = errors[roomId]; - console.error("Failed to leave room " + roomId + " " + err); + for (const leftRoomId of Object.keys(errors)) { + const err = errors[leftRoomId]; + if (!err) continue; + + console.error("Failed to leave room " + leftRoomId + " " + err); let title = _t("Failed to leave room"); let message = _t("Server may be unavailable, overloaded, or you hit a bug."); if (err.errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { From 389abed5745590e1d78b65c5ffc2c48a42bb162e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 22 Mar 2019 19:03:43 -0600 Subject: [PATCH 3/3] Define a title for generic error --- src/components/structures/MatrixChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 26956858be..9d8a4adb6f 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1098,7 +1098,7 @@ export default React.createClass({ modal.close(); console.error("Failed to leave room " + roomId + " " + err); Modal.createTrackedDialog('Failed to leave room', '', ErrorDialog, { - title: title, + title: _t("Failed to leave room"), description: _t("Unknown error"), }); });