From 88536b1bc358043b7e69e9c4387977b97c413c50 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Tue, 19 Nov 2024 17:40:50 +0100 Subject: [PATCH] Revert "Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `SendMessageComposer.tsx`" This reverts commit 6bf06da02ca2c0cf72f0e12a418d07f05a86da3a. --- .../views/rooms/SendMessageComposer.tsx | 24 +++++++++---------- .../views/rooms/SendMessageComposer-test.tsx | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index ea49e9fcbe3..252957c2c77 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -243,7 +243,7 @@ export class SendMessageComposer extends React.Component; - private prepareToEncrypt?: DebouncedFunc<() => void>; + private readonly prepareToEncrypt?: DebouncedFunc<() => void>; private readonly editorRef = createRef(); private model: EditorModel; private currentlyComposedEditorState: SerializedPart[] | null = null; @@ -253,17 +253,7 @@ export class SendMessageComposer extends React.Component) { super(props, context); - const partCreator = new CommandPartCreator(this.props.room, this.props.mxClient); - const parts = this.restoreStoredEditorState(partCreator) || []; - this.model = new EditorModel(parts, partCreator); - this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, "mx_cider_history_"); - } - - public async componentDidMount(): Promise { - window.addEventListener("beforeunload", this.saveStoredEditorState); - this.dispatcherRef = dis.register(this.onAction); - - if (await this.props.mxClient.getCrypto()?.isEncryptionEnabledInRoom(this.props.room.roomId)) { + if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) { this.prepareToEncrypt = throttle( () => { this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room); @@ -272,6 +262,16 @@ export class SendMessageComposer extends React.Component", () => { it("should call prepareToEncrypt when the user is typing", async () => { const cli = stubClient(); - jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true); + cli.isRoomEncrypted = jest.fn().mockReturnValue(true); const room = mkStubRoom("!roomId:server", "Room", cli); expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled();