don't add retried entries to the timeline if they are not already there

This commit is contained in:
Bruno Windels 2021-03-03 11:27:18 +01:00
parent 7f1cdf6841
commit 43547e0901
2 changed files with 22 additions and 21 deletions

View file

@ -226,8 +226,9 @@ export class Room extends EventEmitter {
/** @package */ /** @package */
async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) { async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) {
log.set("id", this.id); log.set("id", this.id);
const {entries, newLiveKey, memberChanges} = const {entries: newEntries, newLiveKey, memberChanges} =
await log.wrap("syncWriter", log => this._syncWriter.writeSync(roomResponse, txn, log), log.level.Detail); await log.wrap("syncWriter", log => this._syncWriter.writeSync(roomResponse, txn, log), log.level.Detail);
let allEntries = newEntries;
if (decryptChanges) { if (decryptChanges) {
const decryption = await decryptChanges.write(txn); const decryption = await decryptChanges.write(txn);
log.set("decryptionResults", decryption.results.size); log.set("decryptionResults", decryption.results.size);
@ -235,14 +236,13 @@ export class Room extends EventEmitter {
if (this._isTimelineOpen) { if (this._isTimelineOpen) {
await decryption.verifySenders(txn); await decryption.verifySenders(txn);
} }
decryption.applyToEntries(newEntries);
if (retryEntries?.length) { if (retryEntries?.length) {
// prepend the retried entries, as we know they are older decryption.applyToEntries(retryEntries);
// (not that it should matter much for the summary) allEntries = retryEntries.concat(allEntries);
entries.unshift(...retryEntries);
} }
decryption.applyToEntries(entries);
} }
log.set("entries", entries.length); log.set("allEntries", allEntries.length);
let shouldFlushKeyShares = false; let shouldFlushKeyShares = false;
// pass member changes to device tracker // pass member changes to device tracker
if (roomEncryption && this.isTrackingMembers && memberChanges?.size) { if (roomEncryption && this.isTrackingMembers && memberChanges?.size) {
@ -251,7 +251,7 @@ export class Room extends EventEmitter {
} }
// also apply (decrypted) timeline entries to the summary changes // also apply (decrypted) timeline entries to the summary changes
summaryChanges = summaryChanges.applyTimelineEntries( summaryChanges = summaryChanges.applyTimelineEntries(
entries, isInitialSync, !this._isTimelineOpen, this._user.id); allEntries, isInitialSync, !this._isTimelineOpen, this._user.id);
// write summary changes, and unset if nothing was actually changed // write summary changes, and unset if nothing was actually changed
summaryChanges = this._summary.writeData(summaryChanges, txn); summaryChanges = this._summary.writeData(summaryChanges, txn);
if (summaryChanges) { if (summaryChanges) {
@ -274,7 +274,8 @@ export class Room extends EventEmitter {
return { return {
summaryChanges, summaryChanges,
roomEncryption, roomEncryption,
newAndUpdatedEntries: entries, newEntries,
updatedEntries: retryEntries || [],
newLiveKey, newLiveKey,
removedPendingEvents, removedPendingEvents,
memberChanges, memberChanges,
@ -288,7 +289,12 @@ export class Room extends EventEmitter {
* Called with the changes returned from `writeSync` to apply them and emit changes. * Called with the changes returned from `writeSync` to apply them and emit changes.
* No storage or network operations should be done here. * No storage or network operations should be done here.
*/ */
afterSync({summaryChanges, newAndUpdatedEntries, newLiveKey, removedPendingEvents, memberChanges, heroChanges, roomEncryption}, log) { afterSync(changes, log) {
const {
summaryChanges, newEntries, updatedEntries, newLiveKey,
removedPendingEvents, memberChanges,
heroChanges, roomEncryption
} = changes;
log.set("id", this.id); log.set("id", this.id);
this._syncWriter.afterSync(newLiveKey); this._syncWriter.afterSync(newLiveKey);
this._setEncryption(roomEncryption); this._setEncryption(roomEncryption);
@ -321,10 +327,13 @@ export class Room extends EventEmitter {
this._emitUpdate(); this._emitUpdate();
} }
if (this._timeline) { if (this._timeline) {
this._timeline.appendLiveEntries(newAndUpdatedEntries); // these should not be added if not already there
this._timeline.replaceEntries(updatedEntries);
this._timeline.addOrReplaceEntries(newEntries);
} }
if (this._observedEvents) { if (this._observedEvents) {
this._observedEvents.updateEvents(newAndUpdatedEntries); this._observedEvents.updateEvents(updatedEntries);
this._observedEvents.updateEvents(newEntries);
} }
if (removedPendingEvents) { if (removedPendingEvents) {
this._sendQueue.emitRemovals(removedPendingEvents); this._sendQueue.emitRemovals(removedPendingEvents);
@ -483,7 +492,7 @@ export class Room extends EventEmitter {
this._sendQueue.emitRemovals(removedPendingEvents); this._sendQueue.emitRemovals(removedPendingEvents);
} }
if (this._timeline) { if (this._timeline) {
this._timeline.addGapEntries(gapResult.entries); this._timeline.addOrReplaceEntries(gapResult.entries);
} }
}); });
} }

View file

@ -60,16 +60,8 @@ export class Timeline {
} }
} }
// TODO: should we rather have generic methods for
// - adding new entries
// - updating existing entries (redaction, relations)
/** @package */ /** @package */
appendLiveEntries(newEntries) { addOrReplaceEntries(newEntries) {
this._remoteEntries.setManySorted(newEntries);
}
/** @package */
addGapEntries(newEntries) {
this._remoteEntries.setManySorted(newEntries); this._remoteEntries.setManySorted(newEntries);
} }