From 4abf18a5f11f4e70b8596fb81a0ed9c56b84472a Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Fri, 25 Nov 2022 11:26:53 +0100 Subject: [PATCH] don't look at tiles before the inserted tile, there is no need also clarify with comments how the current algorithm works --- src/domain/session/room/timeline/TilesCollection.js | 12 ++++++++---- src/domain/session/room/timeline/tiles/DateTile.ts | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index 29e0bdfc..e4ed9d24 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -152,9 +152,11 @@ export class TilesCollection extends BaseObservableList { _evaluateDateHeaderAtIdx(tileIdx) { //console.log("_evaluateDateHeaderAtIdx", tileIdx); - // consider the two adjacent tiles where the previous sibling changed: - // the new tile and the next tile - for (let i = -2; i < 3; i += 1) { + // consider two tiles after the inserted tile, because + // the first of the two tiles may be a DateTile in which case, + // we remove it after looking at the needsDateSeparator prop of the + // next next tile + for (let i = 0; i < 2; i += 1) { const idx = tileIdx + i; if (idx < 0) { continue; @@ -173,10 +175,12 @@ export class TilesCollection extends BaseObservableList { this.emitUpdate(idx - 1, prevTile, "date"); } else { //console.log(" add", idx, tile.shape, tile.eventId); + // adding a tile shift all the indices we need to consider + // especially given we consider removals for the tile that + // comes after a datetile tileIdx += 1; this._addTileAt(idx, tile.createDateSeparator()); } - // TODO must be looking at the wrong index to find the old date separator?? } else if (hasDateSeparator) { // this is never triggered because needsDateSeparator is not cleared // when loading more items because we don't do anything once the diff --git a/src/domain/session/room/timeline/tiles/DateTile.ts b/src/domain/session/room/timeline/tiles/DateTile.ts index 413ec2b2..92bd42e5 100644 --- a/src/domain/session/room/timeline/tiles/DateTile.ts +++ b/src/domain/session/room/timeline/tiles/DateTile.ts @@ -119,6 +119,9 @@ export class DateTile extends ViewModel implements ITile { // let item know it has a new sibling updatePreviousSibling(prev: ITile | undefined): void { + // forward the sibling update to our next tile, so it is informed + // about it's previous sibling beyond the date header (which is it's direct previous sibling) + // so it can recalculate whether it still needs a date header this._firstTileInDay.updatePreviousSibling(prev); }