From 2501bad4b42904246b10601741e9e2a574d4d93f Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 9 Sep 2021 11:14:32 -0700 Subject: [PATCH] Move context fetching into BaseRoom --- src/matrix/room/BaseRoom.js | 16 ++++++++++++++++ src/matrix/room/Room.js | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 4b6fccd7..c8afc3d3 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -311,6 +311,22 @@ export class BaseRoom extends EventEmitter { } } + 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 + // 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, gapResult }; + }, log); + return contextEvent; + } + /** @public */ fillGap(fragmentEntry, amount, log = null) { // TODO move some/all of this out of BaseRoom diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index ec887b23..cab0e13b 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -110,22 +110,6 @@ 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 - // 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, gapResult }; - }, log); - return contextEvent; - } - /** @package */ async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) { log.set("id", this.id);