From d26377f1f40d44f7c4a94985a6e893fa5dd52028 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 6 Dec 2023 17:42:42 +0000 Subject: [PATCH] Move RoomList out of MatrixClient, into legacy Crypto --- spec/unit/crypto.spec.ts | 24 ++++-------------------- src/client.ts | 25 ++++--------------------- src/crypto/index.ts | 25 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/spec/unit/crypto.spec.ts b/spec/unit/crypto.spec.ts index bb21efd34b9..ac1eec9d25d 100644 --- a/spec/unit/crypto.spec.ts +++ b/spec/unit/crypto.spec.ts @@ -356,7 +356,6 @@ describe("Crypto", function () { let crypto: Crypto; let mockBaseApis: MatrixClient; - let mockRoomList: RoomList; let fakeEmitter: EventEmitter; @@ -390,19 +389,10 @@ describe("Crypto", function () { isGuest: jest.fn(), emit: jest.fn(), } as unknown as MatrixClient; - mockRoomList = {} as unknown as RoomList; fakeEmitter = new EventEmitter(); - crypto = new Crypto( - mockBaseApis, - "@alice:home.server", - "FLIBBLE", - clientStore, - cryptoStore, - mockRoomList, - [], - ); + crypto = new Crypto(mockBaseApis, "@alice:home.server", "FLIBBLE", clientStore, cryptoStore, []); crypto.registerEventHandlers(fakeEmitter as any); await crypto.init(); }); @@ -1341,15 +1331,9 @@ describe("Crypto", function () { setRoomEncryption: jest.fn().mockResolvedValue(undefined), } as unknown as RoomList; - crypto = new Crypto( - mockClient, - "@alice:home.server", - "FLIBBLE", - clientStore, - cryptoStore, - mockRoomList, - [], - ); + crypto = new Crypto(mockClient, "@alice:home.server", "FLIBBLE", clientStore, cryptoStore, []); + // @ts-ignore we are injecting a mock into a private property + crypto.roomList = mockRoomList; }); it("should set the algorithm if called for a known room", async () => { diff --git a/src/client.ts b/src/client.ts index a9531fcffc3..b8304b58db7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -51,7 +51,7 @@ import { decodeBase64, encodeBase64 } from "./base64"; import { IExportedDevice as IExportedOlmDevice } from "./crypto/OlmDevice"; import { IOlmDevice } from "./crypto/algorithms/megolm"; import { TypedReEmitter } from "./ReEmitter"; -import { IRoomEncryption, RoomList } from "./crypto/RoomList"; +import { IRoomEncryption } from "./crypto/RoomList"; import { logger, Logger } from "./logger"; import { SERVICE_TYPES } from "./service-types"; import { @@ -1272,7 +1272,6 @@ export class MatrixClient extends TypedEventEmitter; private readonly verificationMethods: Map; public readonly supportedAlgorithms: string[]; @@ -473,10 +474,14 @@ export class Crypto extends TypedEventEmitter, ) { super(); + + logger.debug("Crypto: initialising roomlist..."); + this.roomList = new RoomList(cryptoStore); + this.roomList.init(); + this.reEmitter = new TypedReEmitter(this); if (verificationMethods) { @@ -4236,6 +4241,22 @@ export class Crypto extends TypedEventEmitter