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();