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 1/3] 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 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/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'] + ); +} From ccf3af21f9bde550ab1d60765cf93dd6c2554d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 18 Aug 2021 09:28:44 +0200 Subject: [PATCH 2/3] Allow playback of replied-to voice message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/rooms/ReplyTile.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/ReplyTile.tsx b/src/components/views/rooms/ReplyTile.tsx index 8c0e09c76c4..741a7ac5efd 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; @@ -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 = { From cedf2db9ec01e8287fa65427d1e4a03f44f907c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 18 Aug 2021 09:29:44 +0200 Subject: [PATCH 3/3] Remove unnecessary this.props MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/rooms/ReplyTile.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/views/rooms/ReplyTile.tsx b/src/components/views/rooms/ReplyTile.tsx index 741a7ac5efd..cf7d1ce945e 100644 --- a/src/components/views/rooms/ReplyTile.tsx +++ b/src/components/views/rooms/ReplyTile.tsx @@ -96,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) { @@ -110,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; @@ -130,7 +130,7 @@ export default class ReplyTile extends React.PureComponent { if (needsSenderProfile) { sender = ; } @@ -152,14 +152,14 @@ export default class ReplyTile extends React.PureComponent { { sender }