mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
fix some gap fill errors
This commit is contained in:
parent
d022608a1a
commit
bdad0ad86b
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user