From cd8a0b8aec552c080a718c17ba3a737c610ed5b3 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 28 Sep 2021 03:42:19 -0400 Subject: [PATCH 1/4] If public room creation fails, retry without publishing it (#19194) Signed-off-by: Andrew Ferrazzutti --- src/createRoom.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/createRoom.ts b/src/createRoom.ts index 25e7257289d..746fd638157 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -221,6 +221,14 @@ export default async function createRoom(opts: IOpts): Promise { let roomId; return client.createRoom(createOpts).finally(function() { if (modal) modal.close(); + }).catch(function(err) { + if (err.httpStatus === 403 && err.errcode == "M_UNKNOWN") { + console.warn("Failed to publish room, try again without publishing it"); + createOpts.visibility = Visibility.Private; + return client.createRoom(createOpts); + } else { + return Promise.reject(err); + } }).then(function(res) { roomId = res.room_id; if (opts.dmUserId) { From 71851d80758c76c0cbfe33ecb2e256f0f116bc6b Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 29 Sep 2021 19:00:14 -0400 Subject: [PATCH 2/4] Check error message for room publish failure Signed-off-by: Andrew Ferrazzutti --- src/createRoom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 746fd638157..0d8172c5588 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -222,7 +222,7 @@ export default async function createRoom(opts: IOpts): Promise { return client.createRoom(createOpts).finally(function() { if (modal) modal.close(); }).catch(function(err) { - if (err.httpStatus === 403 && err.errcode == "M_UNKNOWN") { + if (err.httpStatus === 403 && err.errcode === "M_UNKNOWN" && err.data.error === "Not allowed to publish room") { console.warn("Failed to publish room, try again without publishing it"); createOpts.visibility = Visibility.Private; return client.createRoom(createOpts); From 017b2e0444210f1d47e0720af8b21805a62b7454 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 1 Oct 2021 01:42:25 -0400 Subject: [PATCH 3/4] Comment that the room publish failure check is Synapse-specific Signed-off-by: Andrew Ferrazzutti --- src/createRoom.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/createRoom.ts b/src/createRoom.ts index 0d8172c5588..7f915bd0514 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -222,6 +222,10 @@ export default async function createRoom(opts: IOpts): Promise { return client.createRoom(createOpts).finally(function() { if (modal) modal.close(); }).catch(function(err) { + // NB This checks for the Synapse-specific error condition of a room creation + // having been denied because the requesting user wanted to publish the room, + // but the server denies them that permission (via room_list_publication_rules). + // The check below responds by retrying without publishing the room. if (err.httpStatus === 403 && err.errcode === "M_UNKNOWN" && err.data.error === "Not allowed to publish room") { console.warn("Failed to publish room, try again without publishing it"); createOpts.visibility = Visibility.Private; From 073c5307f83459c32a0607d127795fc98bb182f8 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sun, 3 Oct 2021 02:33:25 -0400 Subject: [PATCH 4/4] Close modal after re-attempt of room creation, not before Signed-off-by: Andrew Ferrazzutti --- src/createRoom.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 7f915bd0514..daf8594e23b 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -219,9 +219,7 @@ export default async function createRoom(opts: IOpts): Promise { if (opts.spinner) modal = Modal.createDialog(Spinner, null, 'mx_Dialog_spinner'); let roomId; - return client.createRoom(createOpts).finally(function() { - if (modal) modal.close(); - }).catch(function(err) { + return client.createRoom(createOpts).catch(function(err) { // NB This checks for the Synapse-specific error condition of a room creation // having been denied because the requesting user wanted to publish the room, // but the server denies them that permission (via room_list_publication_rules). @@ -233,6 +231,8 @@ export default async function createRoom(opts: IOpts): Promise { } else { return Promise.reject(err); } + }).finally(function() { + if (modal) modal.close(); }).then(function(res) { roomId = res.room_id; if (opts.dmUserId) {