look for transaction_id in /messages response to delete pending events

This commit is contained in:
Bruno Windels 2020-03-22 00:07:37 +01:00
parent 6d68ec1bac
commit f02641c808
2 changed files with 49 additions and 40 deletions

View file

@ -68,14 +68,35 @@ export default class Room extends EventEmitter {
limit: amount,
filter: {lazy_load_members: true}
}).response();
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.pendingEvents,
this._storage.storeNames.timelineEvents,
this._storage.storeNames.timelineFragments,
]);
let removedPendingEvents;
let newEntries;
try {
// detect remote echos of pending messages in the gap
removedPendingEvents = this._sendQueue.removeRemoteEchos(response.chunk, txn);
// write new events into gap
const gapWriter = new GapWriter({
roomId: this._roomId,
storage: this._storage,
fragmentIdComparer: this._fragmentIdComparer
});
const newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response);
newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response, txn);
} catch (err) {
txn.abort();
throw err;
}
await txn.complete();
// once txn is committed, emit events
if (removedPendingEvents) {
this._sendQueue.emitRemovals(removedPendingEvents);
}
if (this._timeline) {
this._timeline.addGapEntries(newEntries)
this._timeline.addGapEntries(newEntries);
}
}

View file

@ -76,7 +76,7 @@ export default class GapWriter {
txn.timelineFragments.update(fragmentEntry.fragment);
}
async writeFragmentFill(fragmentEntry, response) {
async writeFragmentFill(fragmentEntry, response, txn) {
const {fragmentId, direction} = fragmentEntry;
// chunk is in reverse-chronological order when backwards
const {chunk, start, end} = response;
@ -89,12 +89,6 @@ export default class GapWriter {
throw new Error("Invalid end token in response");
}
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.timelineEvents,
this._storage.storeNames.timelineFragments,
]);
try {
// make sure we have the latest fragment from the store
const fragment = await txn.timelineFragments.get(this._roomId, fragmentId);
if (!fragment) {
@ -116,12 +110,6 @@ export default class GapWriter {
// create entries for all events in chunk, add them to entries
entries = this._storeEvents(nonOverlappingEvents, lastKey, direction, txn);
await this._updateFragments(fragmentEntry, neighbourFragmentEntry, end, entries, txn);
} catch (err) {
txn.abort();
throw err;
}
await txn.complete();
return entries;
}