Propagate updates

This commit is contained in:
RMidhunSuresh 2021-12-15 17:47:14 +05:30
parent 7ef79c92f5
commit 3fe824dbd1
2 changed files with 26 additions and 5 deletions

View File

@ -259,14 +259,30 @@ export class Timeline {
/**
* Update entries based on newly received events.
* eg: a newly received redacted event may mark an existing event in contextEntriesNotInTimeline as being redacted
* This is only for the events that are not in the timeline but had to fetched from elsewhere to render reply previews.
*/
_updateFetchedEntries(entries) {
for (const entry of entries) {
const relatedEntry = this._getTrackedEntry(entry.relatedEventId);
// todo: can this be called .addRelation instead?
if (relatedEntry?.addLocalRelation(entry)) {
relatedEntry.contextForEntries?.forEach(e => this._updateEntry(e));
const relatedEntry = this._contextEntriesNotInTimeline.get(entry.relatedEventId);
if (!relatedEntry) {
continue;
}
// update dependents with this new entry indicating that this is an update to contextEntry
const newEntry = this._createEntryFromRelatedEntries(entry, relatedEntry);
if (newEntry) {
Timeline._entryUpdater(relatedEntry, newEntry);
relatedEntry.contextForEntries?.forEach(e => {
this._remoteEntries.findAndUpdate(te => te.id === e.id, () => { return { reply: newEntry }; });
});
}
}
}
_createEntryFromRelatedEntries(entry, relatedEntry) {
if (entry.isRedaction) {
const newEntry = relatedEntry.clone();
newEntry.setAsRedacted();
return newEntry;
}
}

View File

@ -26,6 +26,7 @@ export class EventEntry extends BaseEventEntry {
this._decryptionResult = null;
this._contextEntry = null;
this._contextForEntries = null;
this._markedAsRedacted = false;
}
clone() {
@ -55,6 +56,10 @@ export class EventEntry extends BaseEventEntry {
this._contextForEntries.push(entry);
}
setAsRedacted() {
this._markedAsRedacted = true;
}
get contextForEntries() {
return this._contextForEntries;
}
@ -153,7 +158,7 @@ export class EventEntry extends BaseEventEntry {
}
get isRedacted() {
return super.isRedacted || isRedacted(this._eventEntry.event);
return this._markedAsRedacted || super.isRedacted || isRedacted(this._eventEntry.event);
}
get redactionReason() {