mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-26 13:05:12 +01:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
|
import EventEmitter from "../../EventEmitter.js";
|
||
|
import RoomTileViewModel from "./RoomTileViewModel.js";
|
||
|
import RoomViewModel from "./RoomViewModel.js";
|
||
|
|
||
|
export default class SessionViewModel extends EventEmitter {
|
||
|
constructor(session) {
|
||
|
super();
|
||
|
this._session = session;
|
||
|
this._currentRoomViewModel = null;
|
||
|
const roomTileVMs = this._session.rooms.mapValues((room, emitUpdate) => {
|
||
|
return new RoomTileViewModel({
|
||
|
room,
|
||
|
emitUpdate,
|
||
|
emitOpen: room => this._openRoom(room)
|
||
|
});
|
||
|
});
|
||
|
this._roomList = roomTileVMs.sortValues((a, b) => a.compare(b));
|
||
|
}
|
||
|
|
||
|
get roomList() {
|
||
|
return this._roomList;
|
||
|
}
|
||
|
|
||
|
get currentRoom() {
|
||
|
return this._currentRoomViewModel;
|
||
|
}
|
||
|
|
||
|
_openRoom(room) {
|
||
|
if (this._currentRoomViewModel) {
|
||
|
this._currentRoomViewModel.disable();
|
||
|
}
|
||
|
this._currentRoomViewModel = new RoomViewModel(room);
|
||
|
this._currentRoomViewModel.enable();
|
||
|
this.emit("change", "currentRoom");
|
||
|
}
|
||
|
}
|
||
|
|