From bdad0ad86b6cb4cf96dcf2aff82ae81e2d1f1c74 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sun, 2 Jun 2019 15:46:24 +0200 Subject: [PATCH] fix some gap fill errors --- src/domain/session/room/timeline/tiles/GapTile.js | 12 +++++++----- src/matrix/room/timeline/Timeline.js | 8 ++++---- src/matrix/room/timeline/persistence/GapWriter.js | 13 +++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index 55bc7429..c063db25 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -12,14 +12,16 @@ export default class GapTile extends SimpleTile { // prevent doing this twice if (!this._loading) { this._loading = true; - this._emitUpdate("isLoading"); + // this._emitUpdate("isLoading"); try { - return await this._timeline.fillGap(this._entry, 10); + await this._timeline.fillGap(this._entry, 10); } catch (err) { - this._loading = false; + console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`); this._error = err; - this._emitUpdate("isLoading"); - this._emitUpdate("error"); + // this._emitUpdate("error"); + } finally { + this._loading = false; + // this._emitUpdate("isLoading"); } } } diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 01483017..52900777 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -4,11 +4,12 @@ import GapWriter from "./persistence/GapWriter.js"; import TimelineReader from "./persistence/TimelineReader.js"; export default class Timeline { - constructor({roomId, storage, closeCallback, fragmentIdComparer}) { + constructor({roomId, storage, closeCallback, fragmentIdComparer, hsApi}) { this._roomId = roomId; this._storage = storage; this._closeCallback = closeCallback; this._fragmentIdComparer = fragmentIdComparer; + this._hsApi = hsApi; this._entriesList = new SortedArray((a, b) => a.compare(b)); this._timelineReader = new TimelineReader({ roomId: this._roomId, @@ -34,14 +35,13 @@ export default class Timeline { from: fragmentEntry.token, dir: fragmentEntry.direction.asApiString(), limit: amount - }); - + }).response(); const gapWriter = new GapWriter({ roomId: this._roomId, storage: this._storage, fragmentIdComparer: this._fragmentIdComparer }); - const newEntries = await gapWriter.writerFragmentFill(fragmentEntry, response); + const newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response); this._entriesList.setManySorted(newEntries); } diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index 415f2292..ad721586 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -47,9 +47,10 @@ export default class GapWriter { const reducer = direction.isBackward ? Array.prototype.reduceRight : Array.prototype.reduce; reducer.call(events, (key, event, i) => { key = key.nextKeyForDirection(direction); - const eventEntry = createEventEntry(key, event); + const eventEntry = createEventEntry(key, this._roomId, event); txn.timelineEvents.insert(eventEntry); entries[i] = new EventEntry(eventEntry, this._fragmentIdComparer); + return key; }, startKey); return entries; } @@ -61,7 +62,7 @@ export default class GapWriter { if (neighbourFragmentEntry) { fragmentEntry.linkedFragmentId = neighbourFragmentEntry.fragmentId; neighbourFragmentEntry.linkedFragmentId = fragmentEntry.fragmentId; - txn.timelineFragments.set(neighbourFragmentEntry.fragment); + txn.timelineFragments.update(neighbourFragmentEntry.fragment); directionalAppend(entries, neighbourFragmentEntry, direction); // update fragmentIdComparer here after linking up fragments @@ -69,7 +70,7 @@ export default class GapWriter { this._fragmentIdComparer.add(neighbourFragmentEntry.fragment); } fragmentEntry.token = end; - txn.timelineFragments.set(fragmentEntry.fragment); + txn.timelineFragments.update(fragmentEntry.fragment); } async writeFragmentFill(fragmentEntry, response) { @@ -92,7 +93,7 @@ export default class GapWriter { try { // make sure we have the latest fragment from the store - const fragment = await txn.timelineFragments.get(fragmentId); + const fragment = await txn.timelineFragments.get(this._roomId, fragmentId); if (!fragment) { throw new Error(`Unknown fragment: ${fragmentId}`); } @@ -102,12 +103,12 @@ export default class GapWriter { throw new Error("start is not equal to prev_batch or next_batch"); } // find last event in fragment so we get the eventIndex to begin creating keys at - let lastKey = this._findLastFragmentEventKey(fragmentEntry, txn); + let lastKey = await this._findLastFragmentEventKey(fragmentEntry, txn); // find out if any event in chunk is already present using findFirstOrLastOccurringEventId const { nonOverlappingEvents, neighbourFragmentEntry - } = this._findOverlappingEvents(fragmentEntry, chunk, txn); + } = await this._findOverlappingEvents(fragmentEntry, chunk, txn); // create entries for all events in chunk, add them to entries entries = this._storeEvents(nonOverlappingEvents, lastKey, direction, txn);