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) {
const filteredEntries = entries.filter(e => !!e.contextEventId);
for (const entry of filteredEntries) {
const entriesNeedingContext = entries.filter(e => !!e.contextEventId);
for (const entry of entriesNeedingContext) {
const id = entry.contextEventId;
let needToTrack = false;
let contextEvent;
// find in remote events
contextEvent = this.getByEventId(id);
// find in storage
let contextEvent = this.getByEventId(id);
if (!contextEvent) {
needToTrack = true;
contextEvent = await this._fetchEventFromStorage(id);
}
// fetch from hs
if (!contextEvent) {
contextEvent = await this._fetchEventFromHomeserver(id);
}
if (contextEvent) {
if (needToTrack) {
contextEvent = await this._fetchEventFromStorage(id) ?? await this._fetchEventFromHomeserver(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
this._fetchedEventEntries.push(contextEvent);
}
if (contextEvent) {
contextEvent.addDependent(entry);
entry.setContextEntry(contextEvent);
// emit this change