From c3da7496ae046e4102245fd27447edadc391914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 18 Aug 2021 09:28:27 +0200 Subject: [PATCH] Add isVoiceMessage() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/MVoiceOrAudioBody.tsx | 6 ++---- src/utils/EventUtils.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/views/messages/MVoiceOrAudioBody.tsx b/src/components/views/messages/MVoiceOrAudioBody.tsx index 2d78ea192e..5a7e34b8a1 100644 --- a/src/components/views/messages/MVoiceOrAudioBody.tsx +++ b/src/components/views/messages/MVoiceOrAudioBody.tsx @@ -19,14 +19,12 @@ import MAudioBody from "./MAudioBody"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import MVoiceMessageBody from "./MVoiceMessageBody"; import { IBodyProps } from "./IBodyProps"; +import { isVoiceMessage } from "../../../utils/EventUtils"; @replaceableComponent("views.messages.MVoiceOrAudioBody") export default class MVoiceOrAudioBody extends React.PureComponent { public render() { - // MSC2516 is a legacy identifier. See https://github.com/matrix-org/matrix-doc/pull/3245 - const isVoiceMessage = !!this.props.mxEvent.getContent()['org.matrix.msc2516.voice'] - || !!this.props.mxEvent.getContent()['org.matrix.msc3245.voice']; - if (isVoiceMessage) { + if (isVoiceMessage(this.props.mxEvent)) { return ; } else { return ; diff --git a/src/utils/EventUtils.ts b/src/utils/EventUtils.ts index 7aef05c523..4af114294f 100644 --- a/src/utils/EventUtils.ts +++ b/src/utils/EventUtils.ts @@ -139,3 +139,12 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent): { return { tileHandler, isInfoMessage, isBubbleMessage }; } + +export function isVoiceMessage(mxEvent: MatrixEvent): boolean { + const content = mxEvent.getContent(); + // MSC2516 is a legacy identifier. See https://github.com/matrix-org/matrix-doc/pull/3245 + return ( + !!content['org.matrix.msc2516.voice'] || + !!content['org.matrix.msc3245.voice'] + ); +}