From 889f4dd1040b6b451f5ff23e1a52bd0087d45688 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 9 Sep 2021 10:53:09 -0700 Subject: [PATCH] Return fetched or retrieved entry from GapWriter --- src/matrix/room/Room.js | 3 +++ src/matrix/room/timeline/persistence/GapWriter.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 20a3efca..578a8e7f 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -112,14 +112,17 @@ export class Room extends BaseRoom { async fetchContext(eventId, log = null) { const response = await this._hsApi.context(this._roomId, eventId, {}, {log}).response(); + let contextEvent = null; await this._fetchEvents(async (txn, gapWriter) => { // Just in case we somehow receive remote echoes during event fetch const beforeExtra = await this._writeGapFill(response.events_before, txn, log); const afterExtra = await this._writeGapFill(response.events_after, txn, log); beforeExtra.push(...afterExtra); const gapResult = await gapWriter.writeContext(response, txn, log); + contextEvent = gapResult.contextEvent; return { extraGapFillChanges: beforeExtra, gapResult }; }, log); + return contextEvent; } /** @package */ diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index b03626b4..67fee305 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -230,7 +230,7 @@ export class GapWriter { const eventEntry = await txn.timelineEvents.getByEventId(this._roomId, event.event_id); if (eventEntry) { // 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); @@ -256,6 +256,7 @@ export class GapWriter { // may as well modify one of them in-place instead of returning a third. startFill.entries.push(...endFill.entries); startFill.updatedEntries.push(...endFill.updatedEntries); + startFill.contextEvent = startFill.entries.find(e => e.id === event.event_id); startFill.fragments.push(...endFill.fragments); if (!startFill.fragments.includes(newFragment)) { // We created the fragment so it is updated.