From 0af9f1016605d3bee38b0122cfb569b361ace741 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 14 Jan 2022 19:11:40 +0530 Subject: [PATCH] don't store tilesCreator --- .../session/room/timeline/TilesCollection.js | 2 +- .../room/timeline/tiles/BaseMessageTile.js | 19 ++++++------------- .../session/room/timeline/tilesCreator.js | 5 ++--- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index 54ab5ddd..33ae4472 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -150,7 +150,7 @@ export class TilesCollection extends BaseObservableList { const tileIdx = this._findTileIdx(entry); const tile = this._findTileAtIdx(entry, tileIdx); if (tile) { - const action = tile.updateEntry(entry, params); + const action = tile.updateEntry(entry, params, this._tileCreator); if (action.shouldReplace) { const newTile = this._tileCreator(entry); if (newTile) { diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index 6e40cef8..0e1de27c 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -21,7 +21,6 @@ import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../ export class BaseMessageTile extends SimpleTile { constructor(options) { super(options); - this._tilesCreator = options.tilesCreator; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; this._isContinuation = false; this._reactions = null; @@ -116,17 +115,17 @@ export class BaseMessageTile extends SimpleTile { } } - updateEntry(entry, param) { + updateEntry(entry, param, tilesCreator) { const replyEntry = entry.contextEntry; - if (replyEntry && this._replyTile) { + if (replyEntry) { // this is an update to contextEntry used for replyPreview - const action = this._replyTile.updateEntry(replyEntry); - if (action?.shouldReplace) { + const action = this._replyTile?.updateEntry(replyEntry); + if (action?.shouldReplace || !this._replyTile) { this.disposeTracked(this._replyTile); - this._replyTile = this._tilesCreator(replyEntry); + this._replyTile = tilesCreator(replyEntry); } if(action?.shouldUpdate) { - this._replyTile.emitChange(); + this._replyTile?.emitChange(); } } const action = super.updateEntry(entry, param); @@ -233,12 +232,6 @@ export class BaseMessageTile extends SimpleTile { if (!this._entry.contextEventId) { return null; } - if (!this._replyTile) { - const entry = this._entry.contextEntry; - if (entry) { - this._replyTile = this.track(this._tilesCreator(entry)); - } - } return this._replyTile; } } diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index 945d9843..9dde00a2 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -28,8 +28,8 @@ import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js"; import {MissingAttachmentTile} from "./tiles/MissingAttachmentTile.js"; export function tilesCreator(baseOptions) { - const creator = function tilesCreator(entry, emitUpdate) { - const options = Object.assign({entry, emitUpdate, tilesCreator: creator}, baseOptions); + return function tilesCreator(entry, emitUpdate) { + const options = Object.assign({entry, emitUpdate}, baseOptions); if (entry.isGap) { return new GapTile(options); } else if (entry.isPending && entry.pendingEvent.isMissingAttachments) { @@ -77,5 +77,4 @@ export function tilesCreator(baseOptions) { } } } - return creator; }