From 0e8039f02d8e5f40d31c2b8e1ab752f3ad7bfb6e Mon Sep 17 00:00:00 2001 From: N-Pex Date: Wed, 25 Nov 2020 15:07:51 +0100 Subject: [PATCH] Fix room not loaded when joining --- src/components/Join.vue | 2 +- src/services/matrix.service.js | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/Join.vue b/src/components/Join.vue index a0026f3..58c5f6d 100644 --- a/src/components/Join.vue +++ b/src/components/Join.vue @@ -50,7 +50,7 @@ export default { return this.$matrix.matrixClient.joinRoom(this.roomId); }) .then((room) => { - this.$matrix.setCurrentRoomId(room.roomId); + this.$matrix.setCurrentRoom(room); this.loading = false; this.loadingMessage = null; this.$router.replace({ name: "Chat" }); diff --git a/src/services/matrix.service.js b/src/services/matrix.service.js index 2f1a963..540b2d1 100644 --- a/src/services/matrix.service.js +++ b/src/services/matrix.service.js @@ -176,12 +176,14 @@ export default { addMatrixClientListeners(client) { if (client) { client.on("event", this.onEvent); + client.on("Room", this.onRoom); } }, removeMatrixClientListeners(client) { if (client) { client.off("event", this.onEvent); + client.off("Room", this.onRoom); } }, @@ -205,6 +207,10 @@ export default { } }, + onRoom(ignoredroom) { + this.reloadRooms(); + }, + reloadRooms() { this.rooms = this.matrixClient.getVisibleRooms(); this.rooms.forEach(room => { @@ -212,15 +218,25 @@ export default { }); }, + setCurrentRoom(room) { + // If we don't know about this room yet (e.g. we just joined) + // add it to our list. + if (!this.getRoom(room.roomId)) { + this.rooms.push(room); + } + this.setCurrentRoomId(room.roomId); + }, + setCurrentRoomId(roomId) { this.$store.commit("setCurrentRoomId", roomId); }, getRoom(roomId) { - // if (this.matrixClient) { - // return this.matrixClient.getRoom(roomId); - // } - return this.rooms.find(room => room.roomId == roomId); + var room = this.rooms.find(room => room.roomId == roomId); + if (!room && this.matrixClient) { + room = this.matrixClient.getRoom(roomId); + } + return room; }, on(event, handler) {