From 8592fcf8c7d692779c168ef3b1f0f8944d364450 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 7 Sep 2021 13:28:28 -0700 Subject: [PATCH] Add experimental code to fetch an event's context --- src/matrix/room/Room.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index cab0e13b..59471a13 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -110,6 +110,18 @@ export class Room extends BaseRoom { } } + async fetchContext(eventId, log = null) { + const response = await this._hsApi.context(this._roomId, eventId, {}, {log}).response(); + await this._fetchEvents(response, 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.append(...afterExtra); + const gapResult = await gapWriter.writeContext(response, txn, log); + return { extraGapFillChanges: beforeExtra, gapResult }; + }, log); + } + /** @package */ async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) { log.set("id", this.id);