From 6bf06da02ca2c0cf72f0e12a418d07f05a86da3a Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 14 Nov 2024 17:59:40 +0100 Subject: [PATCH] Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `SendMessageComposer.tsx` --- .../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 252957c2c7..ea49e9fcbe 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 readonly prepareToEncrypt?: DebouncedFunc<() => void>; + private prepareToEncrypt?: DebouncedFunc<() => void>; private readonly editorRef = createRef(); private model: EditorModel; private currentlyComposedEditorState: SerializedPart[] | null = null; @@ -253,7 +253,17 @@ export class SendMessageComposer extends React.Component) { super(props, context); - if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) { + 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)) { this.prepareToEncrypt = throttle( () => { this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room); @@ -262,16 +272,6 @@ export class SendMessageComposer extends React.Component", () => { it("should call prepareToEncrypt when the user is typing", async () => { const cli = stubClient(); - cli.isRoomEncrypted = jest.fn().mockReturnValue(true); + jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true); const room = mkStubRoom("!roomId:server", "Room", cli); expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled();