Lift tilesCreator to the room's level

This commit is contained in:
Danila Fedorin 2021-08-04 11:17:27 -07:00
parent 960e3ec469
commit 2169f68a7f
2 changed files with 9 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import {TimelineViewModel} from "./timeline/TimelineViewModel.js";
import {ComposerViewModel} from "./ComposerViewModel.js" import {ComposerViewModel} from "./ComposerViewModel.js"
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
import {ViewModel} from "../../ViewModel.js"; import {ViewModel} from "../../ViewModel.js";
import {tilesCreator} from "./timeline/tilesCreator.js";
export class RoomViewModel extends ViewModel { export class RoomViewModel extends ViewModel {
constructor(options) { constructor(options) {
@ -30,6 +31,7 @@ export class RoomViewModel extends ViewModel {
this._timelineError = null; this._timelineError = null;
this._sendError = null; this._sendError = null;
this._composerVM = null; this._composerVM = null;
this._tilesCreator = null;
if (room.isArchived) { if (room.isArchived) {
this._composerVM = new ArchivedViewModel(this.childOptions({archivedRoom: room})); this._composerVM = new ArchivedViewModel(this.childOptions({archivedRoom: room}));
} else { } else {
@ -43,12 +45,15 @@ export class RoomViewModel extends ViewModel {
this._room.on("change", this._onRoomChange); this._room.on("change", this._onRoomChange);
try { try {
const timeline = await this._room.openTimeline(); const timeline = await this._room.openTimeline();
const timelineVM = this.track(new TimelineViewModel(this.childOptions({ this._tilesCreator = tilesCreator(this.childOptions({
room: this._room, room: this._room,
roomVM: this, roomVM: this,
timeline, timeline,
}));
this._timelineVM = this.track(new TimelineViewModel(this.childOptions({
tilesCreator: this._tilesCreator,
timeline
}))); })));
this._timelineVM = timelineVM;
this.emitChange("timelineViewModel"); this.emitChange("timelineViewModel");
} catch (err) { } catch (err) {
console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`); console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`);

View File

@ -38,9 +38,9 @@ import {ViewModel} from "../../../ViewModel.js";
export class TimelineViewModel extends ViewModel { export class TimelineViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
const {room, timeline, roomVM} = options; const {timeline, tilesCreator} = options;
this._timeline = this.track(timeline); this._timeline = this.track(timeline);
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline, roomVM}))); this._tiles = new TilesCollection(timeline.entries, tilesCreator);
} }
/** /**