From a0c3a3ab06f8b5590440ec26b60609df8b128d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 10 May 2022 19:22:39 +0200 Subject: [PATCH] Fix download button not working on events that were decrypted too late (#8556) --- src/components/views/messages/MessageEvent.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index d52629b56d..a47b70a7a8 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -20,6 +20,7 @@ import { Relations } from 'matrix-js-sdk/src/models/relations'; import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon'; import { M_LOCATION } from 'matrix-js-sdk/src/@types/location'; import { M_POLL_START } from "matrix-events-sdk"; +import { MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import SettingsStore from "../../../settings/SettingsStore"; import { Mjolnir } from "../../../mjolnir/Mjolnir"; @@ -73,7 +74,12 @@ export default class MessageEvent extends React.Component implements IMe } } + public componentDidMount(): void { + this.props.mxEvent.addListener(MatrixEventEvent.Decrypted, this.onDecrypted); + } + public componentWillUnmount() { + this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted); this.mediaHelper?.destroy(); } @@ -118,6 +124,14 @@ export default class MessageEvent extends React.Component implements IMe return this.mediaHelper; } + private onDecrypted = (): void => { + // Recheck MediaEventHelper eligibility as it can change when the event gets decrypted + if (MediaEventHelper.isEligible(this.props.mxEvent)) { + this.mediaHelper?.destroy(); + this.mediaHelper = new MediaEventHelper(this.props.mxEvent); + } + }; + private onTileUpdate = () => { this.forceUpdate(); };