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();