From 0bf021ea87f24ea029a6c86ea9c8859214aa0a33 Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:37:03 +0200 Subject: [PATCH] The room is now joined after having actualised the rooms list, to avoid the synchronisations waits that can sometimes disable to enter the room (message "You're not into this room" or simply "You're not in this room yet. *Join the room*") --- src/domain/session/room/RoomViewModel.js | 2 +- src/matrix/Session.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index b3fc703c..a15447b8 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -210,8 +210,8 @@ export class RoomViewModel extends ViewModel { if (args.length == 1) { let roomName = args[0]; try { - await this._options.client.session.joinRoom(roomName); const internalId = await this._options.client.session.joinRoom(roomName); + await this._options.client.session.waitForRoomFromSync(internalId); this.navigation.push("room", internalId); } catch (exc) { if ((exc.statusCode ?? exc.status) === 400) { diff --git a/src/matrix/Session.js b/src/matrix/Session.js index ae1dea61..f45cb5b3 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -948,6 +948,23 @@ export class Session { return body.room_id; }); } + + waitForRoomFromSync(roomId) { + let resolve; + const promise = new Promise(r => { resolve = r; }) + const subscription = { + onAdd: (_, value) => { + if (value.id === roomId) { + this._session.rooms.unsubscribe(subscription); + resolve(); + } + }, + onUpdate: () => undefined, + onRemove: () => undefined, + }; + this._session.rooms.subscribe(subscription); + return promise; + } } export function tests() {