Merge pull request #438 from vector-im/bwindels/fix-401

Fix error when back-paginating reaction on event in unloaded fragment
This commit is contained in:
Bruno Windels 2021-08-04 14:49:04 +00:00 committed by GitHub
commit 790724bc2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -127,6 +127,10 @@ class Island {
} }
} }
export class CompareError extends Error {
get name() { return "CompareError"; }
}
/* /*
index for fast lookup of how two fragments can be sorted index for fast lookup of how two fragments can be sorted
*/ */
@ -139,7 +143,7 @@ export class FragmentIdComparer {
_getIsland(id) { _getIsland(id) {
const island = this._idToIsland.get(id); const island = this._idToIsland.get(id);
if (island === undefined) { if (island === undefined) {
throw new Error(`Unknown fragment id ${id}`); throw new CompareError(`Unknown fragment id ${id}`);
} }
return island; return island;
} }
@ -151,7 +155,7 @@ export class FragmentIdComparer {
const islandA = this._getIsland(idA); const islandA = this._getIsland(idA);
const islandB = this._getIsland(idB); const islandB = this._getIsland(idB);
if (islandA !== islandB) { if (islandA !== islandB) {
throw new Error(`${idA} and ${idB} are on different islands, can't tell order`); throw new CompareError(`${idA} and ${idB} are on different islands, can't tell order`);
} }
return islandA.compare(idA, idB); return islandA.compare(idA, idB);
} }

View file

@ -212,7 +212,22 @@ export class Timeline {
replaceEntries(entries) { replaceEntries(entries) {
this._addLocalRelationsToNewRemoteEntries(entries); this._addLocalRelationsToNewRemoteEntries(entries);
for (const entry of entries) { for (const entry of entries) {
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater); try {
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater);
} catch (err) {
if (err.name === "CompareError") {
// see FragmentIdComparer, if the replacing entry is on a fragment
// that is currently not loaded into the FragmentIdComparer, it will
// throw a CompareError, and it means that the event is not loaded
// in the timeline (like when receiving a relation for an event
// that is not loaded in memory) so we can just drop this error as
// replacing an event that is not already loaded is a no-op.
continue;
} else {
// don't swallow other errors
throw err;
}
}
} }
} }