From d50dae52082a09d9b640a8ab6935e7314fcd1e14 Mon Sep 17 00:00:00 2001 From: Germain Date: Wed, 2 Mar 2022 09:02:14 +0000 Subject: [PATCH] Decrypt thread last reply on EventTile mount and update (#7930) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/rooms/EventTile.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index e5c7989518..62784f6d5c 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -514,6 +514,11 @@ export default class EventTile extends React.Component { const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); room?.on(ThreadEvent.New, this.onNewThread); + + if (this.state.threadLastReply?.isEncrypted()) { + this.state.threadLastReply.once(MatrixEventEvent.Decrypted, this.onEventDecryption); + MatrixClientPeg.get().decryptEventIfNeeded(this.state.threadLastReply); + } } private setupNotificationListener = (thread: Thread): void => { @@ -596,6 +601,7 @@ export default class EventTile extends React.Component { if (this.threadState) { this.threadState.off(NotificationStateEvents.Update, this.onThreadStateUpdate); } + this.state.threadLastReply?.removeListener(MatrixEventEvent.Decrypted, this.onEventDecryption); } componentDidUpdate(prevProps: IProps, prevState: IState, snapshot) { @@ -604,8 +610,20 @@ export default class EventTile extends React.Component { MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt); this.isListeningForReceipts = true; } + + if (this.state.threadLastReply !== prevState.threadLastReply) { + if (this.state.threadLastReply.isEncrypted()) { + this.state.threadLastReply.once(MatrixEventEvent.Decrypted, this.onEventDecryption); + MatrixClientPeg.get().decryptEventIfNeeded(this.state.threadLastReply); + } + prevState.threadLastReply?.removeListener(MatrixEventEvent.Decrypted, this.onEventDecryption); + } } + private onEventDecryption = () => { + this.forceUpdate(); + }; + private onNewThread = (thread: Thread) => { if (thread.id === this.props.mxEvent.getId()) { this.updateThread(thread);