Made code more readable

This commit is contained in:
RMidhunSuresh 2021-12-12 18:34:02 +05:30
parent 287212956b
commit 4a6293dcdc

View file

@ -262,28 +262,17 @@ export class Timeline {
} }
async _loadRelatedEvents(entries) { async _loadRelatedEvents(entries) {
const filteredEntries = entries.filter(e => !!e.contextEventId); const entriesNeedingContext = entries.filter(e => !!e.contextEventId);
for (const entry of filteredEntries) { for (const entry of entriesNeedingContext) {
const id = entry.contextEventId; const id = entry.contextEventId;
let needToTrack = false; let contextEvent = this.getByEventId(id);
let contextEvent;
// find in remote events
contextEvent = this.getByEventId(id);
// find in storage
if (!contextEvent) { if (!contextEvent) {
needToTrack = true; contextEvent = await this._fetchEventFromStorage(id) ?? await this._fetchEventFromHomeserver(id);
contextEvent = await this._fetchEventFromStorage(id); // this entry was created from storage/hs, so it's not tracked by remoteEntries
} // we track them here so that we can update reply preview of dependents on redaction
// fetch from hs this._fetchedEventEntries.push(contextEvent);
if (!contextEvent) {
contextEvent = await this._fetchEventFromHomeserver(id);
} }
if (contextEvent) { if (contextEvent) {
if (needToTrack) {
// this entry was created from storage/hs, so it's not tracked by remoteEntries
// we track them here so that we can update reply preview of dependents on redaction
this._fetchedEventEntries.push(contextEvent);
}
contextEvent.addDependent(entry); contextEvent.addDependent(entry);
entry.setContextEntry(contextEvent); entry.setContextEntry(contextEvent);
// emit this change // emit this change