From 3bb1422f93a188e2de7c09055bac2964d799ac60 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 18 Mar 2020 19:23:36 -0400 Subject: [PATCH] pre-send megolm keys when possible when a user starts typing --- src/components/views/rooms/SendMessageComposer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index 63e58bf738..31085ad6db 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -42,6 +42,8 @@ import {_t, _td} from '../../../languageHandler'; import ContentMessages from '../../../ContentMessages'; import {Key} from "../../../Keyboard"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; +import {MatrixClientPeg} from "../../../MatrixClientPeg"; +import RateLimitedFunc from '../../../ratelimitedfunc'; function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) { const replyContent = ReplyThread.makeReplyMixIn(repliedToEvent); @@ -102,6 +104,12 @@ export default class SendMessageComposer extends React.Component { this.model = null; this._editorRef = null; this.currentlyComposedEditorState = null; + const cli = MatrixClientPeg.get(); + if (cli.isCryptoEnabled() && cli.isRoomEncrypted(this.props.room.roomId)) { + this._prepareToEncrypt = new RateLimitedFunc(() => { + cli.prepareToEncrypt(this.props.room); + }, 60000); + } } _setEditorRef = ref => { @@ -121,6 +129,8 @@ export default class SendMessageComposer extends React.Component { this.onVerticalArrow(event, true); } else if (event.key === Key.ARROW_DOWN) { this.onVerticalArrow(event, false); + } else if (this._prepareToEncrypt) { + this._prepareToEncrypt(); } }