use addLocalRelation
This commit is contained in:
parent
7ad73bb453
commit
ec8f6e8e0a
2 changed files with 7 additions and 45 deletions
|
@ -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.
|
* This is specific to events that are not in the timeline but had to be fetched from the homeserver.
|
||||||
*/
|
*/
|
||||||
_updateEntriesFetchedFromHomeserver(entries) {
|
_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) {
|
for (const entry of entries) {
|
||||||
const relatedEntry = this._contextEntriesNotInTimeline.get(entry.relatedEventId);
|
const relatedEntry = this._contextEntriesNotInTimeline.get(entry.relatedEventId);
|
||||||
if (!relatedEntry) {
|
if (relatedEntry?.addLocalRelation(entry)) {
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
// update other entries for which this entry is a context entry
|
// update other entries for which this entry is a context entry
|
||||||
relatedEntry.contextForEntries?.forEach(e => {
|
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),
|
* 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
|
* remove the event from _contextEntriesNotInTimeline since it is now in remoteEntries
|
||||||
|
|
|
@ -15,7 +15,6 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {EventEntry} from "./EventEntry.js";
|
import {EventEntry} from "./EventEntry.js";
|
||||||
import {redactEvent} from "../common.js";
|
|
||||||
|
|
||||||
// EventEntry but without the two properties that are populated via SyncWriter
|
// EventEntry but without the two properties that are populated via SyncWriter
|
||||||
// Useful if you want to create an EventEntry that is ephemeral
|
// Useful if you want to create an EventEntry that is ephemeral
|
||||||
|
@ -28,21 +27,4 @@ export class NonPersistedEventEntry extends EventEntry {
|
||||||
get entryIndex() {
|
get entryIndex() {
|
||||||
throw new Error("Cannot access entryIndex for non-persisted EventEntry");
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue