Return fetched or retrieved entry from GapWriter

This commit is contained in:
Danila Fedorin 2021-09-09 10:53:09 -07:00
parent 7f91e0c1bd
commit 889f4dd104
2 changed files with 5 additions and 1 deletions

View file

@ -112,14 +112,17 @@ export class Room extends BaseRoom {
async fetchContext(eventId, log = null) { async fetchContext(eventId, log = null) {
const response = await this._hsApi.context(this._roomId, eventId, {}, {log}).response(); const response = await this._hsApi.context(this._roomId, eventId, {}, {log}).response();
let contextEvent = null;
await this._fetchEvents(async (txn, gapWriter) => { await this._fetchEvents(async (txn, gapWriter) => {
// Just in case we somehow receive remote echoes during event fetch // Just in case we somehow receive remote echoes during event fetch
const beforeExtra = await this._writeGapFill(response.events_before, txn, log); const beforeExtra = await this._writeGapFill(response.events_before, txn, log);
const afterExtra = await this._writeGapFill(response.events_after, txn, log); const afterExtra = await this._writeGapFill(response.events_after, txn, log);
beforeExtra.push(...afterExtra); beforeExtra.push(...afterExtra);
const gapResult = await gapWriter.writeContext(response, txn, log); const gapResult = await gapWriter.writeContext(response, txn, log);
contextEvent = gapResult.contextEvent;
return { extraGapFillChanges: beforeExtra, gapResult }; return { extraGapFillChanges: beforeExtra, gapResult };
}, log); }, log);
return contextEvent;
} }
/** @package */ /** @package */

View file

@ -230,7 +230,7 @@ export class GapWriter {
const eventEntry = await txn.timelineEvents.getByEventId(this._roomId, event.event_id); const eventEntry = await txn.timelineEvents.getByEventId(this._roomId, event.event_id);
if (eventEntry) { if (eventEntry) {
// If we have the current event, eary return. // If we have the current event, eary return.
return { entries: [], updatedEntries: [], fragments: [] } return { entries: [], updatedEntries: [], fragments: [], contextEvent: new EventEntry(eventEntry, this._fragmentIdComparer) }
} }
const maxFragmentKey = await txn.timelineFragments.getMaxFragmentId(this._roomId); const maxFragmentKey = await txn.timelineFragments.getMaxFragmentId(this._roomId);
@ -256,6 +256,7 @@ export class GapWriter {
// may as well modify one of them in-place instead of returning a third. // may as well modify one of them in-place instead of returning a third.
startFill.entries.push(...endFill.entries); startFill.entries.push(...endFill.entries);
startFill.updatedEntries.push(...endFill.updatedEntries); startFill.updatedEntries.push(...endFill.updatedEntries);
startFill.contextEvent = startFill.entries.find(e => e.id === event.event_id);
startFill.fragments.push(...endFill.fragments); startFill.fragments.push(...endFill.fragments);
if (!startFill.fragments.includes(newFragment)) { if (!startFill.fragments.includes(newFragment)) {
// We created the fragment so it is updated. // We created the fragment so it is updated.