diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index 7366641b..e3d92171 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -43,7 +43,7 @@ export class TimelineViewModel extends ViewModel { // once we support sending messages we could do // timeline.entries.concat(timeline.pendingEvents) // for an ObservableList that also contains local echos - this._tiles = new TilesCollection(timeline.entries, tilesCreator({room, ownUserId, platform: this.platform})); + this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, ownUserId}))); } async load() { diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index 98d197b9..c2cf2f56 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -18,22 +18,25 @@ import {SimpleTile} from "./SimpleTile.js"; import {UpdateAction} from "../UpdateAction.js"; export class GapTile extends SimpleTile { - constructor(options, timeline) { + constructor(options) { super(options); - this._timeline = timeline; this._loading = false; this._error = null; } + get _room() { + return this.getOption("room"); + } + async fill() { // prevent doing this twice if (!this._loading) { this._loading = true; this.emitChange("isLoading"); try { - await this._timeline.fillGap(this._entry, 10); + await this._room.fillGap(this._entry, 10); } catch (err) { - console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`); + console.error(`room.fillGap(): ${err.message}:\n${err.stack}`); this._error = err; this.emitChange("error"); // rethrow so caller of this method diff --git a/src/domain/session/room/timeline/tiles/MessageTile.js b/src/domain/session/room/timeline/tiles/MessageTile.js index 36d08ca7..fe566814 100644 --- a/src/domain/session/room/timeline/tiles/MessageTile.js +++ b/src/domain/session/room/timeline/tiles/MessageTile.js @@ -20,12 +20,19 @@ import {getIdentifierColorNumber, avatarInitials} from "../../../../avatar.js"; export class MessageTile extends SimpleTile { constructor(options) { super(options); - this._mediaRepository = options.mediaRepository; this._isOwn = this._entry.sender === options.ownUserId; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; this._isContinuation = false; } + get _room() { + return this.getOption("room"); + } + + get _mediaRepository() { + return this._room.mediaRepository; + } + get shape() { return "message"; } diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index d682d22e..549ad65d 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -23,12 +23,11 @@ import {RoomMemberTile} from "./tiles/RoomMemberTile.js"; import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js"; import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js"; -export function tilesCreator({room, ownUserId, platform}) { +export function tilesCreator(baseOptions) { return function tilesCreator(entry, emitUpdate) { - const options = {entry, emitUpdate, ownUserId, platform, - mediaRepository: room.mediaRepository}; + const options = Object.assign({entry, emitUpdate}, baseOptions); if (entry.isGap) { - return new GapTile(options, room); + return new GapTile(options); } else if (entry.eventType) { switch (entry.eventType) { case "m.room.message": {