2020-04-21 00:56:39 +05:30
|
|
|
import {RoomTileViewModel} from "./roomlist/RoomTileViewModel.js";
|
|
|
|
import {RoomViewModel} from "./room/RoomViewModel.js";
|
2020-05-06 02:47:27 +05:30
|
|
|
import {SessionStatusViewModel} from "./SessionStatusViewModel.js";
|
2020-05-04 22:53:11 +05:30
|
|
|
import {ViewModel} from "../ViewModel.js";
|
2019-02-28 03:20:08 +05:30
|
|
|
|
2020-05-04 22:53:11 +05:30
|
|
|
export class SessionViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2020-05-06 02:47:27 +05:30
|
|
|
const {sessionContainer} = options;
|
2020-04-23 00:22:56 +05:30
|
|
|
this._session = sessionContainer.session;
|
2020-05-06 02:46:51 +05:30
|
|
|
this._sessionStatusViewModel = this.track(new SessionStatusViewModel(this.childOptions({
|
2020-05-07 03:35:21 +05:30
|
|
|
sync: sessionContainer.sync,
|
2020-05-06 02:46:51 +05:30
|
|
|
reconnector: sessionContainer.reconnector
|
|
|
|
})));
|
2019-02-28 03:20:08 +05:30
|
|
|
this._currentRoomViewModel = null;
|
|
|
|
const roomTileVMs = this._session.rooms.mapValues((room, emitUpdate) => {
|
2019-06-27 02:44:39 +05:30
|
|
|
return new RoomTileViewModel({
|
|
|
|
room,
|
|
|
|
emitUpdate,
|
|
|
|
emitOpen: room => this._openRoom(room)
|
2019-02-28 03:20:08 +05:30
|
|
|
});
|
2019-06-27 02:44:39 +05:30
|
|
|
});
|
2019-02-28 03:20:08 +05:30
|
|
|
this._roomList = roomTileVMs.sortValues((a, b) => a.compare(b));
|
|
|
|
}
|
|
|
|
|
2020-05-06 02:46:51 +05:30
|
|
|
start() {
|
|
|
|
this._sessionStatusViewModel.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
get sessionStatusViewModel() {
|
|
|
|
return this._sessionStatusViewModel;
|
2019-06-16 14:24:16 +05:30
|
|
|
}
|
|
|
|
|
2019-02-28 03:20:08 +05:30
|
|
|
get roomList() {
|
|
|
|
return this._roomList;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentRoom() {
|
|
|
|
return this._currentRoomViewModel;
|
|
|
|
}
|
|
|
|
|
2019-06-27 02:44:39 +05:30
|
|
|
_closeCurrentRoom() {
|
|
|
|
if (this._currentRoomViewModel) {
|
2020-05-06 02:47:27 +05:30
|
|
|
this._currentRoomViewModel = this.disposeTracked(this._currentRoomViewModel);
|
2020-05-04 22:53:11 +05:30
|
|
|
this.emitChange("currentRoom");
|
2019-06-27 02:44:39 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-28 03:20:08 +05:30
|
|
|
_openRoom(room) {
|
|
|
|
if (this._currentRoomViewModel) {
|
2020-05-06 02:47:27 +05:30
|
|
|
this._currentRoomViewModel = this.disposeTracked(this._currentRoomViewModel);
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|
2020-05-06 02:47:27 +05:30
|
|
|
this._currentRoomViewModel = this.track(new RoomViewModel(this.childOptions({
|
2019-06-27 02:44:39 +05:30
|
|
|
room,
|
2019-07-29 13:53:15 +05:30
|
|
|
ownUserId: this._session.user.id,
|
2019-06-27 02:44:39 +05:30
|
|
|
closeCallback: () => this._closeCurrentRoom(),
|
2020-05-06 02:47:27 +05:30
|
|
|
})));
|
2019-06-27 02:44:39 +05:30
|
|
|
this._currentRoomViewModel.load();
|
2020-05-04 22:53:11 +05:30
|
|
|
this.emitChange("currentRoom");
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|