From 9dfa01e1a8190d827f0dda574e8e882e5239ace1 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Mon, 16 Aug 2021 15:30:48 +0200 Subject: [PATCH] Fix error on accessing encrypted media without keys In case where the message is encrypted and you request cross-signed keys from another session you may end up in a situation where `media` doesn't exist as you didn't receive keys, yet you have the message's type. This commit fixes this problem by checking if the media is even available. --- src/components/views/messages/MFileBody.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/messages/MFileBody.tsx b/src/components/views/messages/MFileBody.tsx index 13fc4b01e7..216a0f6cbf 100644 --- a/src/components/views/messages/MFileBody.tsx +++ b/src/components/views/messages/MFileBody.tsx @@ -178,7 +178,7 @@ export default class MFileBody extends React.Component { private onPlaceholderClick = async () => { const mediaHelper = this.props.mediaEventHelper; - if (mediaHelper.media.isEncrypted) { + if (mediaHelper?.media.isEncrypted) { await this.decryptFile(); this.downloadFile(this.fileName, this.linkText); } else { @@ -192,7 +192,7 @@ export default class MFileBody extends React.Component { }; public render() { - const isEncrypted = this.props.mediaEventHelper.media.isEncrypted; + const isEncrypted = this.props.mediaEventHelper?.media.isEncrypted; const contentUrl = this.getContentUrl(); const fileSize = this.content.info ? this.content.info.size : null; const fileType = this.content.info ? this.content.info.mimetype : "application/octet-stream";