diff --git a/src/components/views/messages/MVoiceOrAudioBody.tsx b/src/components/views/messages/MVoiceOrAudioBody.tsx index 2d78ea192e8..5a7e34b8a1f 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/components/views/rooms/ReplyTile.tsx b/src/components/views/rooms/ReplyTile.tsx index 8c0e09c76c4..cf7d1ce945e 100644 --- a/src/components/views/rooms/ReplyTile.tsx +++ b/src/components/views/rooms/ReplyTile.tsx @@ -25,8 +25,9 @@ import MImageReplyBody from "../messages/MImageReplyBody"; import * as sdk from '../../../index'; import { EventType, MsgType } from 'matrix-js-sdk/src/@types/event'; import { replaceableComponent } from '../../../utils/replaceableComponent'; -import { getEventDisplayInfo } from '../../../utils/EventUtils'; +import { getEventDisplayInfo, isVoiceMessage } from '../../../utils/EventUtils'; import MFileBody from "../messages/MFileBody"; +import MVoiceMessageBody from "../messages/MVoiceMessageBody"; interface IProps { mxEvent: MatrixEvent; @@ -95,7 +96,7 @@ export default class ReplyTile extends React.PureComponent { const msgType = mxEvent.getContent().msgtype; const evType = mxEvent.getType() as EventType; - const { tileHandler, isInfoMessage } = getEventDisplayInfo(this.props.mxEvent); + const { tileHandler, isInfoMessage } = getEventDisplayInfo(mxEvent); // This shouldn't happen: the caller should check we support this type // before trying to instantiate us if (!tileHandler) { @@ -109,14 +110,14 @@ export default class ReplyTile extends React.PureComponent { const EventTileType = sdk.getComponent(tileHandler); const classes = classNames("mx_ReplyTile", { - mx_ReplyTile_info: isInfoMessage && !this.props.mxEvent.isRedacted(), + mx_ReplyTile_info: isInfoMessage && !mxEvent.isRedacted(), mx_ReplyTile_audio: msgType === MsgType.Audio, mx_ReplyTile_video: msgType === MsgType.Video, }); let permalink = "#"; if (this.props.permalinkCreator) { - permalink = this.props.permalinkCreator.forEvent(this.props.mxEvent.getId()); + permalink = this.props.permalinkCreator.forEvent(mxEvent.getId()); } let sender; @@ -129,7 +130,7 @@ export default class ReplyTile extends React.PureComponent { if (needsSenderProfile) { sender = ; } @@ -137,7 +138,7 @@ export default class ReplyTile extends React.PureComponent { const msgtypeOverrides = { [MsgType.Image]: MImageReplyBody, // Override audio and video body with file body. We also hide the download/decrypt button using CSS - [MsgType.Audio]: MFileBody, + [MsgType.Audio]: isVoiceMessage(mxEvent) ? MVoiceMessageBody : MFileBody, [MsgType.Video]: MFileBody, }; const evOverrides = { @@ -151,14 +152,14 @@ export default class ReplyTile extends React.PureComponent { { sender } diff --git a/src/utils/EventUtils.ts b/src/utils/EventUtils.ts index 7aef05c5234..4af114294f7 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'] + ); +}