From 5b868a9064b4f39a9d7e6eb71cd88feb7db8fbb8 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 9 Sep 2021 11:12:04 -0700 Subject: [PATCH] Only call room-specific gap filling hooks once --- src/matrix/room/Room.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 578a8e7f..ec887b23 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -110,17 +110,18 @@ 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(); 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); + // Keep events in order just in case. + const allEvents = response.events_before.slice().reverse(); + allEvents.push(response.event, ...response.events_after); + const extraGapFillChanges = await this._writeGapFill(allEvents, txn, log); const gapResult = await gapWriter.writeContext(response, txn, log); contextEvent = gapResult.contextEvent; - return { extraGapFillChanges: beforeExtra, gapResult }; + return { extraGapFillChanges, gapResult }; }, log); return contextEvent; }