forked from mystiq/hydrogen-web
adjust tiles(collection) to entry changes
This commit is contained in:
parent
35d90a8535
commit
039bbe038c
5 changed files with 25 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
||||||
import BaseObservableList from "../../../../observable/list/BaseObservableList.js";
|
import BaseObservableList from "../../../../observable/list/BaseObservableList.js";
|
||||||
import sortedIndex from "../../../../utils/sortedIndex.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 {
|
export default class TilesCollection extends BaseObservableList {
|
||||||
constructor(entries, tileCreator) {
|
constructor(entries, tileCreator) {
|
||||||
super();
|
super();
|
||||||
|
@ -39,16 +39,16 @@ export default class TilesCollection extends BaseObservableList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_findTileIdx(sortKey) {
|
_findTileIdx(entry) {
|
||||||
return sortedIndex(this._tiles, sortKey, (key, tile) => {
|
return sortedIndex(this._tiles, entry, (entry, tile) => {
|
||||||
// negate result because we're switching the order of the params
|
// 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);
|
const tile = this._getTileAtIdx(idx);
|
||||||
if (tile && tile.compareSortKey(sortKey) === 0) {
|
if (tile && tile.compareEntry(entry) === 0) {
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,7 @@ export default class TilesCollection extends BaseObservableList {
|
||||||
}
|
}
|
||||||
|
|
||||||
onAdd(index, entry) {
|
onAdd(index, entry) {
|
||||||
const {sortKey} = entry;
|
const tileIdx = this._findTileIdx(entry);
|
||||||
const tileIdx = this._findTileIdx(sortKey);
|
|
||||||
const prevTile = this._getTileAtIdx(tileIdx - 1);
|
const prevTile = this._getTileAtIdx(tileIdx - 1);
|
||||||
if (prevTile && prevTile.tryIncludeEntry(entry)) {
|
if (prevTile && prevTile.tryIncludeEntry(entry)) {
|
||||||
this.emitUpdate(tileIdx - 1, prevTile);
|
this.emitUpdate(tileIdx - 1, prevTile);
|
||||||
|
@ -98,9 +97,8 @@ export default class TilesCollection extends BaseObservableList {
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdate(index, entry, params) {
|
onUpdate(index, entry, params) {
|
||||||
const {sortKey} = entry;
|
const tileIdx = this._findTileIdx(entry);
|
||||||
const tileIdx = this._findTileIdx(sortKey);
|
const tile = this._findTileAtIdx(entry, tileIdx);
|
||||||
const tile = this._findTileAtIdx(sortKey, tileIdx);
|
|
||||||
if (tile) {
|
if (tile) {
|
||||||
const newParams = tile.updateEntry(entry, params);
|
const newParams = tile.updateEntry(entry, params);
|
||||||
if (newParams) {
|
if (newParams) {
|
||||||
|
@ -122,9 +120,8 @@ export default class TilesCollection extends BaseObservableList {
|
||||||
|
|
||||||
// would also be called when unloading a part of the timeline
|
// would also be called when unloading a part of the timeline
|
||||||
onRemove(index, entry) {
|
onRemove(index, entry) {
|
||||||
const {sortKey} = entry;
|
const tileIdx = this._findTileIdx(entry);
|
||||||
const tileIdx = this._findTileIdx(sortKey);
|
const tile = this._findTileAtIdx(entry, tileIdx);
|
||||||
const tile = this._findTileAtIdx(sortKey, tileIdx);
|
|
||||||
if (tile) {
|
if (tile) {
|
||||||
const removeTile = tile.removeEntry(entry);
|
const removeTile = tile.removeEntry(entry);
|
||||||
if (removeTile) {
|
if (removeTile) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default class GapTile extends SimpleTile {
|
||||||
}
|
}
|
||||||
|
|
||||||
get direction() {
|
get direction() {
|
||||||
return this._entry.prev_batch ? "backward" : "forward";
|
return this._entry.direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
get error() {
|
get error() {
|
||||||
|
|
|
@ -18,18 +18,19 @@ export default class SimpleTile {
|
||||||
get hasDateSeparator() {
|
get hasDateSeparator() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// TilesCollection contract? unused atm
|
||||||
get upperSortKey() {
|
get upperEntry() {
|
||||||
return this._entry.sortKey;
|
return this._entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
get lowerSortKey() {
|
// TilesCollection contract? unused atm
|
||||||
return this._entry.sortKey;
|
get lowerEntry() {
|
||||||
|
return this._entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TilesCollection contract
|
// TilesCollection contract
|
||||||
compareSortKey(key) {
|
compareEntry(entry) {
|
||||||
return this._entry.sortKey.compare(key);
|
return this._entry.compare(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update received for already included (falls within sort keys) entry
|
// update received for already included (falls within sort keys) entry
|
||||||
|
|
|
@ -8,7 +8,7 @@ import RoomMemberTile from "./tiles/RoomMemberTile.js";
|
||||||
export default function ({timeline, emitUpdate}) {
|
export default function ({timeline, emitUpdate}) {
|
||||||
return function tilesCreator(entry) {
|
return function tilesCreator(entry) {
|
||||||
const options = {entry, emitUpdate};
|
const options = {entry, emitUpdate};
|
||||||
if (entry.gap) {
|
if (entry.isGap) {
|
||||||
return new GapTile(options, timeline);
|
return new GapTile(options, timeline);
|
||||||
} else if (entry.event) {
|
} else if (entry.event) {
|
||||||
const event = entry.event;
|
const event = entry.event;
|
||||||
|
|
|
@ -18,6 +18,10 @@ export default class EventEntry extends BaseEntry {
|
||||||
return this._eventEntry.event.content;
|
return this._eventEntry.event.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get event() {
|
||||||
|
return this._eventEntry.event;
|
||||||
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
return this._eventEntry.event.type;
|
return this._eventEntry.event.type;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue