2021-06-17 14:12:43 +05:30
|
|
|
import {ViewModel} from "../../ViewModel.js";
|
|
|
|
import {RoomDetailsViewModel} from "./RoomDetailsViewModel.js";
|
2021-06-17 15:17:02 +05:30
|
|
|
import {MemberListViewModel} from "./MemberListViewModel.js";
|
2021-06-17 14:12:43 +05:30
|
|
|
|
|
|
|
export class RightPanelViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
this._room = options.room;
|
|
|
|
this._setupNavigation();
|
|
|
|
}
|
|
|
|
|
2021-06-27 18:10:50 +05:30
|
|
|
get activeViewModel() { return this._activeViewModel; }
|
2021-06-17 14:12:43 +05:30
|
|
|
|
2021-06-30 15:35:48 +05:30
|
|
|
async _getMemberArguments() {
|
2021-06-27 18:10:50 +05:30
|
|
|
const list = await this._room.loadMemberList();
|
|
|
|
const room = this._room;
|
2021-07-14 12:59:44 +05:30
|
|
|
const powerLevelsObservable = await this._room.observePowerLevels();
|
|
|
|
return {members: list.members, powerLevelsObservable, mediaRepository: room.mediaRepository};
|
2021-06-27 18:10:50 +05:30
|
|
|
}
|
2021-06-17 15:17:02 +05:30
|
|
|
|
2021-06-27 18:10:50 +05:30
|
|
|
_setupNavigation() {
|
2021-06-30 15:35:48 +05:30
|
|
|
this._hookUpdaterToSegment("details", RoomDetailsViewModel, () => { return {room: this._room}; });
|
|
|
|
this._hookUpdaterToSegment("members", MemberListViewModel, () => this._getMemberArguments());
|
2021-06-17 14:12:43 +05:30
|
|
|
}
|
|
|
|
|
2021-06-30 15:35:48 +05:30
|
|
|
_hookUpdaterToSegment(segment, viewmodel, argCreator) {
|
2021-06-27 18:10:50 +05:30
|
|
|
const observable = this.navigation.observe(segment);
|
2021-06-30 15:35:48 +05:30
|
|
|
const updater = this._setupUpdater(segment, viewmodel, argCreator);
|
|
|
|
this.track(observable.subscribe(() => updater()));
|
2021-06-17 14:12:43 +05:30
|
|
|
}
|
2021-06-17 15:17:02 +05:30
|
|
|
|
2021-06-30 15:35:48 +05:30
|
|
|
_setupUpdater(segment, viewmodel, argCreator) {
|
|
|
|
const updater = async (skipDispose = false) => {
|
2021-06-27 18:10:50 +05:30
|
|
|
if (!skipDispose) {
|
|
|
|
this._activeViewModel = this.disposeTracked(this._activeViewModel);
|
|
|
|
}
|
|
|
|
const enable = !!this.navigation.path.get(segment)?.value;
|
|
|
|
if (enable) {
|
|
|
|
const args = await argCreator();
|
|
|
|
this._activeViewModel = this.track(new viewmodel(this.childOptions(args)));
|
|
|
|
}
|
|
|
|
this.emitChange("activeViewModel");
|
|
|
|
};
|
2021-06-30 15:35:48 +05:30
|
|
|
updater(true);
|
|
|
|
return updater;
|
2021-06-17 15:17:02 +05:30
|
|
|
}
|
2021-06-17 14:12:43 +05:30
|
|
|
}
|