From 2169f68a7ffd20eab566fab61e9741ea5aea4806 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 4 Aug 2021 11:17:27 -0700 Subject: [PATCH] Lift tilesCreator to the room's level --- src/domain/session/room/RoomViewModel.js | 9 +++++++-- src/domain/session/room/timeline/TimelineViewModel.js | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 11f08df1..d36713bf 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -19,6 +19,7 @@ import {TimelineViewModel} from "./timeline/TimelineViewModel.js"; import {ComposerViewModel} from "./ComposerViewModel.js" import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; import {ViewModel} from "../../ViewModel.js"; +import {tilesCreator} from "./timeline/tilesCreator.js"; export class RoomViewModel extends ViewModel { constructor(options) { @@ -30,6 +31,7 @@ export class RoomViewModel extends ViewModel { this._timelineError = null; this._sendError = null; this._composerVM = null; + this._tilesCreator = null; if (room.isArchived) { this._composerVM = new ArchivedViewModel(this.childOptions({archivedRoom: room})); } else { @@ -43,12 +45,15 @@ export class RoomViewModel extends ViewModel { this._room.on("change", this._onRoomChange); try { const timeline = await this._room.openTimeline(); - const timelineVM = this.track(new TimelineViewModel(this.childOptions({ + this._tilesCreator = tilesCreator(this.childOptions({ room: this._room, roomVM: this, timeline, + })); + this._timelineVM = this.track(new TimelineViewModel(this.childOptions({ + tilesCreator: this._tilesCreator, + timeline }))); - this._timelineVM = timelineVM; this.emitChange("timelineViewModel"); } catch (err) { console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`); diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index 5ec21d9a..bb2cda9b 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -38,9 +38,9 @@ import {ViewModel} from "../../../ViewModel.js"; export class TimelineViewModel extends ViewModel { constructor(options) { super(options); - const {room, timeline, roomVM} = options; + const {timeline, tilesCreator} = options; this._timeline = this.track(timeline); - this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline, roomVM}))); + this._tiles = new TilesCollection(timeline.entries, tilesCreator); } /**