From 039bbe038ccd08b2ef5170083b6e3883176bedad Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sat, 1 Jun 2019 18:29:02 +0200 Subject: [PATCH] adjust tiles(collection) to entry changes --- .../session/room/timeline/TilesCollection.js | 25 ++++++++----------- .../session/room/timeline/tiles/GapTile.js | 2 +- .../session/room/timeline/tiles/SimpleTile.js | 15 +++++------ .../session/room/timeline/tilesCreator.js | 2 +- .../room/timeline/entries/EventEntry.js | 4 +++ 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index 36678764..3c80fc98 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -1,7 +1,7 @@ import BaseObservableList from "../../../../observable/list/BaseObservableList.js"; import sortedIndex from "../../../../utils/sortedIndex.js"; -// maps 1..n entries to 0..1 tile. Entries are what is stored in the timeline, either an event or gap +// maps 1..n entries to 0..1 tile. Entries are what is stored in the timeline, either an event or fragmentboundary export default class TilesCollection extends BaseObservableList { constructor(entries, tileCreator) { super(); @@ -39,16 +39,16 @@ export default class TilesCollection extends BaseObservableList { } } - _findTileIdx(sortKey) { - return sortedIndex(this._tiles, sortKey, (key, tile) => { + _findTileIdx(entry) { + return sortedIndex(this._tiles, entry, (entry, tile) => { // negate result because we're switching the order of the params - return -tile.compareSortKey(key); + return -tile.compareEntry(entry); }); } - _findTileAtIdx(sortKey, idx) { + _findTileAtIdx(entry, idx) { const tile = this._getTileAtIdx(idx); - if (tile && tile.compareSortKey(sortKey) === 0) { + if (tile && tile.compareEntry(entry) === 0) { return tile; } } @@ -72,8 +72,7 @@ export default class TilesCollection extends BaseObservableList { } onAdd(index, entry) { - const {sortKey} = entry; - const tileIdx = this._findTileIdx(sortKey); + const tileIdx = this._findTileIdx(entry); const prevTile = this._getTileAtIdx(tileIdx - 1); if (prevTile && prevTile.tryIncludeEntry(entry)) { this.emitUpdate(tileIdx - 1, prevTile); @@ -98,9 +97,8 @@ export default class TilesCollection extends BaseObservableList { } onUpdate(index, entry, params) { - const {sortKey} = entry; - const tileIdx = this._findTileIdx(sortKey); - const tile = this._findTileAtIdx(sortKey, tileIdx); + const tileIdx = this._findTileIdx(entry); + const tile = this._findTileAtIdx(entry, tileIdx); if (tile) { const newParams = tile.updateEntry(entry, params); if (newParams) { @@ -122,9 +120,8 @@ export default class TilesCollection extends BaseObservableList { // would also be called when unloading a part of the timeline onRemove(index, entry) { - const {sortKey} = entry; - const tileIdx = this._findTileIdx(sortKey); - const tile = this._findTileAtIdx(sortKey, tileIdx); + const tileIdx = this._findTileIdx(entry); + const tile = this._findTileAtIdx(entry, tileIdx); if (tile) { const removeTile = tile.removeEntry(entry); if (removeTile) { diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index fe0cb6fe..cebffe24 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -29,7 +29,7 @@ export default class GapTile extends SimpleTile { } get direction() { - return this._entry.prev_batch ? "backward" : "forward"; + return this._entry.direction; } get error() { diff --git a/src/domain/session/room/timeline/tiles/SimpleTile.js b/src/domain/session/room/timeline/tiles/SimpleTile.js index bacb8259..266b09db 100644 --- a/src/domain/session/room/timeline/tiles/SimpleTile.js +++ b/src/domain/session/room/timeline/tiles/SimpleTile.js @@ -18,18 +18,19 @@ export default class SimpleTile { get hasDateSeparator() { return false; } - - get upperSortKey() { - return this._entry.sortKey; + // TilesCollection contract? unused atm + get upperEntry() { + return this._entry; } - get lowerSortKey() { - return this._entry.sortKey; + // TilesCollection contract? unused atm + get lowerEntry() { + return this._entry; } // TilesCollection contract - compareSortKey(key) { - return this._entry.sortKey.compare(key); + compareEntry(entry) { + return this._entry.compare(entry); } // update received for already included (falls within sort keys) entry diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index e70088b9..732e0ce6 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -8,7 +8,7 @@ import RoomMemberTile from "./tiles/RoomMemberTile.js"; export default function ({timeline, emitUpdate}) { return function tilesCreator(entry) { const options = {entry, emitUpdate}; - if (entry.gap) { + if (entry.isGap) { return new GapTile(options, timeline); } else if (entry.event) { const event = entry.event; diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index 07d00a76..98e961cf 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -18,6 +18,10 @@ export default class EventEntry extends BaseEntry { return this._eventEntry.event.content; } + get event() { + return this._eventEntry.event; + } + get type() { return this._eventEntry.event.type; }