Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `EventIndex.ts`

Florian Duros 2024-11-20 11:01:54 +01:00
parent 7329a5f1fc
commit 21545e3fbd
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15
3 changed files with 19 additions and 13 deletions

View File

@ -67,7 +67,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
let currentRoom: string | null = null; let currentRoom: string | null = null;
if (room) currentRoom = room.name; if (room) currentRoom = room.name;
const roomStats = eventIndex.crawlingRooms(); const roomStats = await eventIndex.crawlingRooms();
const crawlingRoomsCount = roomStats.crawlingRooms.size; const crawlingRoomsCount = roomStats.crawlingRooms.size;
const roomCount = roomStats.totalRooms.size; const roomCount = roomStats.totalRooms.size;
@ -112,7 +112,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
// probably succeed. // probably succeed.
} }
const roomStats = eventIndex.crawlingRooms(); const roomStats = await eventIndex.crawlingRooms();
crawlingRoomsCount = roomStats.crawlingRooms.size; crawlingRoomsCount = roomStats.crawlingRooms.size;
roomCount = roomStats.totalRooms.size; roomCount = roomStats.totalRooms.size;

View File

@ -206,7 +206,7 @@ export default class EventIndex extends EventEmitter {
const client = MatrixClientPeg.safeGet(); const client = MatrixClientPeg.safeGet();
// We only index encrypted rooms locally. // We only index encrypted rooms locally.
if (!client.isRoomEncrypted(ev.getRoomId()!)) return; if (!(await client.getCrypto()?.isEncryptionEnabledInRoom(ev.getRoomId()!))) return;
if (ev.isRedaction()) { if (ev.isRedaction()) {
return this.redactEvent(ev); return this.redactEvent(ev);
@ -223,7 +223,8 @@ export default class EventIndex extends EventEmitter {
}; };
private onRoomStateEvent = async (ev: MatrixEvent, state: RoomState): Promise<void> => { private onRoomStateEvent = async (ev: MatrixEvent, state: RoomState): Promise<void> => {
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))) { if (ev.getType() === EventType.RoomEncryption && !(await this.isRoomIndexed(state.roomId))) {
logger.log("EventIndex: Adding a checkpoint for a newly encrypted room", 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<void> => { private onTimelineReset = async (room: Room | undefined): Promise<void> => {
if (!room) return; 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); 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<string>; crawlingRooms: Set<string>;
totalRooms: Set<string>; totalRooms: Set<string>;
} { }> {
const totalRooms = new Set<string>(); const totalRooms = new Set<string>();
const crawlingRooms = new Set<string>(); const crawlingRooms = new Set<string>();
@ -966,13 +967,12 @@ export default class EventIndex extends EventEmitter {
} }
const client = MatrixClientPeg.safeGet(); const client = MatrixClientPeg.safeGet();
const crypto = client.getCrypto();
const rooms = client.getRooms(); const rooms = client.getRooms();
const isRoomEncrypted = (room: Room): boolean => { const encryptedRooms = crypto
return client.isRoomEncrypted(room.roomId); ? await asyncFilter(rooms, (room) => crypto.isEncryptionEnabledInRoom(room.roomId))
}; : [];
const encryptedRooms = rooms.filter(isRoomEncrypted);
encryptedRooms.forEach((room, index) => { encryptedRooms.forEach((room, index) => {
totalRooms.add(room.roomId); totalRooms.add(room.roomId);
}); });

View File

@ -13,13 +13,19 @@ import { defer, IDeferred } from "matrix-js-sdk/src/utils";
import EventIndexPanel from "../../../../../src/components/views/settings/EventIndexPanel"; import EventIndexPanel from "../../../../../src/components/views/settings/EventIndexPanel";
import EventIndexPeg from "../../../../../src/indexing/EventIndexPeg"; import EventIndexPeg from "../../../../../src/indexing/EventIndexPeg";
import EventIndex from "../../../../../src/indexing/EventIndex"; 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 SettingsStore from "../../../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../../../src/settings/SettingLevel"; import { SettingLevel } from "../../../../../src/settings/SettingLevel";
describe("<EventIndexPanel />", () => { describe("<EventIndexPanel />", () => {
getMockClientWithEventEmitter({ getMockClientWithEventEmitter({
getRooms: jest.fn().mockReturnValue([]), getRooms: jest.fn().mockReturnValue([]),
...mockClientMethodsCrypto(),
}); });
const getComponent = () => render(<EventIndexPanel />); const getComponent = () => render(<EventIndexPanel />);