From 92405c39fc2a4a603acfb402471a6dc8217ea8ba Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 20 Nov 2024 11:01:54 +0100 Subject: [PATCH] Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `EventIndex.ts` --- .../eventindex/ManageEventIndexDialog.tsx | 4 ++-- src/indexing/EventIndex.ts | 20 +++++++++---------- .../views/settings/EventIndexPanel-test.tsx | 8 +++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx index 01b7e8227c..bbce777a89 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx @@ -67,7 +67,7 @@ export default class ManageEventIndexDialog extends React.Component => { - if (!MatrixClientPeg.safeGet().isRoomEncrypted(state.roomId)) return; + const crypto = MatrixClientPeg.safeGet().getCrypto(); + if (!(await crypto?.isEncryptionEnabledInRoom(state.roomId))) return; if (ev.getType() === EventType.RoomEncryption && !(await this.isRoomIndexed(state.roomId))) { logger.log("EventIndex: Adding a checkpoint for a newly encrypted room", state.roomId); @@ -257,7 +258,7 @@ export default class EventIndex extends EventEmitter { */ private onTimelineReset = async (room: Room | undefined): Promise => { if (!room) return; - if (!MatrixClientPeg.safeGet().isRoomEncrypted(room.roomId)) return; + if (!(await MatrixClientPeg.safeGet().getCrypto()?.isEncryptionEnabledInRoom(room.roomId))) return; logger.log("EventIndex: Adding a checkpoint because of a limited timeline", room.roomId); @@ -950,10 +951,10 @@ export default class EventIndex extends EventEmitter { } } - public crawlingRooms(): { + public async crawlingRooms(): Promise<{ crawlingRooms: Set; totalRooms: Set; - } { + }> { const totalRooms = new Set(); const crawlingRooms = new Set(); @@ -966,13 +967,12 @@ export default class EventIndex extends EventEmitter { } const client = MatrixClientPeg.safeGet(); + const crypto = client.getCrypto(); const rooms = client.getRooms(); - const isRoomEncrypted = (room: Room): boolean => { - return client.isRoomEncrypted(room.roomId); - }; - - const encryptedRooms = rooms.filter(isRoomEncrypted); + const encryptedRooms = crypto + ? await asyncFilter(rooms, (room) => crypto.isEncryptionEnabledInRoom(room.roomId)) + : []; encryptedRooms.forEach((room, index) => { totalRooms.add(room.roomId); }); diff --git a/test/unit-tests/components/views/settings/EventIndexPanel-test.tsx b/test/unit-tests/components/views/settings/EventIndexPanel-test.tsx index 9859cc27fa..01951027bc 100644 --- a/test/unit-tests/components/views/settings/EventIndexPanel-test.tsx +++ b/test/unit-tests/components/views/settings/EventIndexPanel-test.tsx @@ -13,13 +13,19 @@ import { defer, IDeferred } from "matrix-js-sdk/src/utils"; import EventIndexPanel from "../../../../../src/components/views/settings/EventIndexPanel"; import EventIndexPeg from "../../../../../src/indexing/EventIndexPeg"; import EventIndex from "../../../../../src/indexing/EventIndex"; -import { clearAllModals, flushPromises, getMockClientWithEventEmitter } from "../../../../test-utils"; +import { + clearAllModals, + flushPromises, + getMockClientWithEventEmitter, + mockClientMethodsCrypto, +} from "../../../../test-utils"; import SettingsStore from "../../../../../src/settings/SettingsStore"; import { SettingLevel } from "../../../../../src/settings/SettingLevel"; describe("", () => { getMockClientWithEventEmitter({ getRooms: jest.fn().mockReturnValue([]), + ...mockClientMethodsCrypto(), }); const getComponent = () => render();