diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 55b3e4f5..ab24ef68 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -265,42 +265,22 @@ export class Timeline { * This is specific to events that are not in the timeline but had to be fetched from the homeserver. */ _updateEntriesFetchedFromHomeserver(entries) { + /** + * Updates for entries in timeline is handled by remoteEntries observable collection + * Updates for entries not in timeline but fetched from storage is handled in this.replaceEntries() + * This code is specific to entries fetched from HomeServer i.e NonPersistedEventEntry + */ for (const entry of entries) { const relatedEntry = this._contextEntriesNotInTimeline.get(entry.relatedEventId); - if (!relatedEntry) { - /** - * Updates for entries in timeline is handled by remoteEntries observable collection - * Updates for entries not in timeline but fetched from storage is handled in this.replaceEntries() - * This code is specific to entries fetched from HomeServer i.e NonPersistedEventEntry - */ - continue; - } - const newEntry = this._createEntryFromRelatedEntries(entry, relatedEntry); - if (newEntry) { - Timeline._entryUpdater(relatedEntry, newEntry); - this._contextEntriesNotInTimeline.set(newEntry.id, newEntry); + if (relatedEntry?.addLocalRelation(entry)) { // update other entries for which this entry is a context entry relatedEntry.contextForEntries?.forEach(e => { - this._remoteEntries.findAndUpdate(te => te.id === e.id, () => { return { reply: newEntry }; }); + this._remoteEntries.findAndUpdate(te => te.id === e.id, () => { return { reply: relatedEntry }; }); }); } } } - /** - * Creates a new entry based on two related entries - * @param {EventEntry} entry an entry - * @param {EventEntry} relatedEntry `entry` specifies something about this entry (eg: this entry is redacted) - * @returns a new entry or undefined - */ - _createEntryFromRelatedEntries(entry, relatedEntry) { - if (entry.isRedaction && relatedEntry.isNonPersisted) { - const newEntry = relatedEntry.clone(); - newEntry.redact(entry); - return newEntry; - } - } - /** * If an event we had to fetch from hs/storage is now in the timeline (for eg, due to gap fill), * remove the event from _contextEntriesNotInTimeline since it is now in remoteEntries diff --git a/src/matrix/room/timeline/entries/NonPersistedEventEntry.js b/src/matrix/room/timeline/entries/NonPersistedEventEntry.js index eebc9273..8ec9f72e 100644 --- a/src/matrix/room/timeline/entries/NonPersistedEventEntry.js +++ b/src/matrix/room/timeline/entries/NonPersistedEventEntry.js @@ -15,7 +15,6 @@ limitations under the License. */ import {EventEntry} from "./EventEntry.js"; -import {redactEvent} from "../common.js"; // EventEntry but without the two properties that are populated via SyncWriter // Useful if you want to create an EventEntry that is ephemeral @@ -28,21 +27,4 @@ export class NonPersistedEventEntry extends EventEntry { get entryIndex() { throw new Error("Cannot access entryIndex for non-persisted EventEntry"); } - - /** - * This method is needed because NonPersistedEventEntry cannot rely on RelationWriter to handle redactions - */ - redact(redactionEvent) { - redactEvent(redactionEvent.event, this.event); - } - - clone() { - const clone = new NonPersistedEventEntry(this._eventEntry, this._fragmentIdComparer); - clone.updateFrom(this); - return clone; - } - - get isNonPersisted() { - return true; - } }