diff options
author | sualko <klaus@jsxc.org> | 2021-08-25 22:58:10 +0300 |
---|---|---|
committer | sualko <klaus@jsxc.org> | 2021-08-25 22:58:10 +0300 |
commit | f3a62c7b8b1c5701d239e409404814014c734b25 (patch) | |
tree | 4eef77e96c4ad7ca6654f2fa401439be7684bcbc | |
parent | e060c0bc3b07559c8fe43c75b2c2184968789f09 (diff) |
fix(muc): create rooms
-rw-r--r-- | src/ui/dialogs/multiUserJoin.ts | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/src/ui/dialogs/multiUserJoin.ts b/src/ui/dialogs/multiUserJoin.ts index 8185032c..b0f2a64f 100644 --- a/src/ui/dialogs/multiUserJoin.ts +++ b/src/ui/dialogs/multiUserJoin.ts @@ -250,24 +250,33 @@ class MultiUserJoinDialog { private continueHandler = ev => { ev.preventDefault(); - this.dom.find('input, select').prop('disabled', true); - this.testInputValues() - .then(this.requestRoomInfo) - .then(this.requestMemberList) - .then(() => { - this.showJoinElements(); - }) - .catch(msg => { - this.dom.find('input, select').prop('disabled', false); - this.setStatusMessage(msg, 'warning'); - - Log.warn(msg); - }); + this.testAndLoadRoomInfo(); return false; }; - private testInputValues(): Promise<JID | void> { + private async testAndLoadRoomInfo() { + this.dom.find('input, select').prop('disabled', true); + + try { + const jid = await this.testInputValues(); + const hasRoomInfo = await this.requestRoomInfo(jid); + + if (hasRoomInfo) { + await this.requestMemberList(jid); + } + + this.showJoinElements(); + } catch (msg) { + this.dom.find('input, select').prop('disabled', false); + + this.setStatusMessage(typeof msg === 'string' ? msg : Translation.t('Can_not_probe_room'), 'warning'); + + Log.warn('Error while probing room', msg); + } + } + + private testInputValues(): Promise<JID> { let room = <string>this.roomInputElement.val(); let server = this.serverInputElement.val() ? this.serverInputElement.val() @@ -302,28 +311,27 @@ class MultiUserJoinDialog { return Promise.resolve(roomJid); } - private requestRoomInfo = (room: JID) => { + private requestRoomInfo = async (room: JID) => { this.setWaitingMessage('Loading_room_information'); - return this.connection - .getDiscoService() - .getDiscoInfo(room) - .then(this.parseRoomInfo) - .then(roomInfoElement => { - this.setStatusElement(roomInfoElement); - }) - .catch(stanza => { - if ($(stanza).find('item-not-found').length > 0) { - this.setStatusMessage(Translation.t('Room_not_found_')); + const discoService = this.connection.getDiscoService(); - return Promise.resolve(); - } + try { + const stanza = await discoService.getDiscoInfo(room); + const roomInfoElement = this.parseRoomInfo(stanza); - return Promise.reject('I was not able to get any room information.'); - }) - .then(() => { - return room; - }); + this.setStatusElement(roomInfoElement); + } catch (errorStanza) { + if ($(errorStanza).find('item-not-found').length > 0) { + this.setStatusMessage(Translation.t('Room_not_found_')); + + return false; + } + + await Promise.reject('I was not able to get any room information.'); + } + + return true; }; private parseRoomInfo = stanza => { |