From ea89c272b9183f62212f842347e6ccd9d093fcce Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 8 Dec 2021 17:14:17 +0530 Subject: [PATCH] Support redaction changes in remoteEntries --- src/matrix/room/timeline/Timeline.js | 5 +++++ src/matrix/room/timeline/entries/EventEntry.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index bc81008d..6d4f0398 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -209,6 +209,8 @@ export class Timeline { // used in replaceEntries static _entryUpdater(existingEntry, entry) { + // ensure dependents point to the new entry instead of existingEntry + existingEntry.dependents?.forEach(event => event.setContextEntry(entry)); entry.updateFrom(existingEntry); return entry; } @@ -220,6 +222,8 @@ export class Timeline { for (const entry of entries) { try { this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater); + // Since this entry changed, all dependent entries should be updated + entry.dependents?.forEach(e => this._findAndUpdateRelatedEntry(null, e.id, () => true)); } catch (err) { if (err.name === "CompareError") { // see FragmentIdComparer, if the replacing entry is on a fragment @@ -251,6 +255,7 @@ export class Timeline { let contextEvent; // find in remote events contextEvent = this.getByEventId(id); + contextEvent?.addDependent(entry); // find in storage if (!contextEvent) { contextEvent = await this._fetchEventFromStorage(id); diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index 064d7f01..c656dfb5 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -25,6 +25,7 @@ export class EventEntry extends BaseEventEntry { this._decryptionError = null; this._decryptionResult = null; this._contextEntry = null; + this._dependents = null; } clone() { @@ -40,12 +41,24 @@ export class EventEntry extends BaseEventEntry { if (other._decryptionError && !this._decryptionError) { this._decryptionError = other._decryptionError; } + this._dependents = other._dependents; } setContextEntry(entry) { this._contextEntry = entry; } + addDependent(entry) { + if (!this._dependents) { + this._dependents = []; + } + this._dependents.push(entry); + } + + get dependents() { + return this._dependents; + } + get event() { return this._eventEntry.event; }