diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index 15c30218..8dc3d224 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -25,10 +25,20 @@ export class LeftPanelViewModel extends ViewModel { super(options); const {rooms} = options; this._roomTileViewModels = rooms.mapValues((room, emitChange) => { - return new RoomTileViewModel(this.childOptions({ + const isOpen = this.navigation.path.get("room")?.value === room.id; + const vm = new RoomTileViewModel(this.childOptions({ + isOpen, room, emitChange })); + // need to also update the current vm here as + // we can't call `_open` from the ctor as the map + // is only populated when the view subscribes. + if (isOpen) { + this._currentTileVM?.close(); + this._currentTileVM = vm; + } + return vm; }); this._roomListFilterMap = new ApplyMap(this._roomTileViewModels); this._roomList = this._roomListFilterMap.sortValues((a, b) => a.compare(b)); @@ -39,7 +49,6 @@ export class LeftPanelViewModel extends ViewModel { _setupNavigation() { const roomObservable = this.navigation.observe("room"); this.track(roomObservable.subscribe(roomId => this._open(roomId))); - this._open(roomObservable.get()); const gridObservable = this.navigation.observe("rooms"); this.gridEnabled = !!gridObservable.get(); diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index a1e43d9f..09cb6372 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -31,6 +31,9 @@ export class RoomTileViewModel extends ViewModel { this._wasUnreadWhenOpening = false; this._hidden = false; this._url = this.urlRouter.openRoomActionUrl(this._room.id); + if (options.isOpen) { + this.open(); + } } get hidden() {