From d3281db2bf160e0b8f4a2ba88ec90f9f927faf12 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 22 Jan 2021 17:49:18 -0700 Subject: [PATCH] Update widgets in the room upon join --- src/stores/WidgetStore.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/stores/WidgetStore.ts b/src/stores/WidgetStore.ts index c53c85dfd5..4ff39aaaee 100644 --- a/src/stores/WidgetStore.ts +++ b/src/stores/WidgetStore.ts @@ -72,6 +72,7 @@ export default class WidgetStore extends AsyncStoreWithClient { } protected async onReady(): Promise { + this.matrixClient.on("Room", this.onRoom); this.matrixClient.on("RoomState.events", this.onRoomStateEvents); this.matrixClient.getRooms().forEach((room: Room) => { this.loadRoomWidgets(room); @@ -80,6 +81,7 @@ export default class WidgetStore extends AsyncStoreWithClient { } protected async onNotReady(): Promise { + this.matrixClient.off("Room", this.onRoom); this.matrixClient.off("RoomState.events", this.onRoomStateEvents); this.widgetMap = new Map(); this.roomMap = new Map(); @@ -138,6 +140,12 @@ export default class WidgetStore extends AsyncStoreWithClient { this.emit(room.roomId); } + private onRoom = (room: Room) => { + this.initRoom(room.roomId); + this.loadRoomWidgets(room); + this.emit(UPDATE_EVENT, room.roomId); + }; + private onRoomStateEvents = (ev: MatrixEvent) => { if (ev.getType() !== "im.vector.modular.widgets") return; // TODO: Support m.widget too const roomId = ev.getRoomId();