From bce02634f79d6fba8d0aa8fda9e233a5ed14b192 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Tue, 15 Oct 2024 09:50:38 +0200 Subject: [PATCH] Replace `MatrixClient.prepareToEncrypt` by `MatrixClient.getCrypto.prepareToEncrypt` (#146) --- src/LegacyCallHandler.tsx | 2 +- src/components/views/rooms/SendMessageComposer.tsx | 2 +- test/LegacyCallHandler-test.ts | 1 - test/components/views/rooms/SendMessageComposer-test.tsx | 7 +++---- test/test-utils/test-utils.ts | 1 + 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/LegacyCallHandler.tsx b/src/LegacyCallHandler.tsx index a19a4d4573..ae14b31aed 100644 --- a/src/LegacyCallHandler.tsx +++ b/src/LegacyCallHandler.tsx @@ -367,7 +367,7 @@ export default class LegacyCallHandler extends EventEmitter { // the mapped one: that's where we'll send the events. const cli = MatrixClientPeg.safeGet(); const room = cli.getRoom(call.roomId); - if (room) cli.prepareToEncrypt(room); + if (room) cli.getCrypto()?.prepareToEncrypt(room); }; public getCallById(callId: string): MatrixCall | null { diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 1b3fb47163..30c11428fc 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -268,7 +268,7 @@ export class SendMessageComposer extends React.Component { - this.props.mxClient.prepareToEncrypt(this.props.room); + this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room); }, 60000, { leading: true, trailing: false }, diff --git a/test/LegacyCallHandler-test.ts b/test/LegacyCallHandler-test.ts index 7bd8c9cc24..08ef133b5f 100644 --- a/test/LegacyCallHandler-test.ts +++ b/test/LegacyCallHandler-test.ts @@ -588,7 +588,6 @@ describe("LegacyCallHandler without third party protocols", () => { jest.spyOn(MatrixClientPeg.safeGet(), "supportsVoip").mockReturnValue(true); MatrixClientPeg.safeGet().isFallbackICEServerAllowed = jest.fn(); - MatrixClientPeg.safeGet().prepareToEncrypt = jest.fn(); MatrixClientPeg.safeGet().pushRules = { global: { diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index a78c9d3e4e..1d1efca7fb 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -573,10 +573,9 @@ describe("", () => { const cli = stubClient(); cli.isCryptoEnabled = jest.fn().mockReturnValue(true); cli.isRoomEncrypted = jest.fn().mockReturnValue(true); - cli.prepareToEncrypt = jest.fn(); const room = mkStubRoom("!roomId:server", "Room", cli); - expect(cli.prepareToEncrypt).not.toHaveBeenCalled(); + expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled(); const { container } = render( @@ -588,9 +587,9 @@ describe("", () => { // Does not trigger on keydown as that'll cause false negatives for global shortcuts await userEvent.type(composer, "[ControlLeft>][KeyK][/ControlLeft]"); - expect(cli.prepareToEncrypt).not.toHaveBeenCalled(); + expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled(); await userEvent.type(composer, "Hello"); - expect(cli.prepareToEncrypt).toHaveBeenCalled(); + expect(cli.getCrypto()!.prepareToEncrypt).toHaveBeenCalled(); }); }); diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 2f534c7bd7..6573285423 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -133,6 +133,7 @@ export function createTestClient(): MatrixClient { isEncryptionEnabledInRoom: jest.fn(), getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]), setDeviceIsolationMode: jest.fn(), + prepareToEncrypt: jest.fn(), }), getPushActionsForEvent: jest.fn(),