Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 623f2e7

Browse files
committed
Only show download link below media if it's not in the timeline
1 parent 7ba0adb commit 623f2e7

File tree

5 files changed

+33
-45
lines changed

5 files changed

+33
-45
lines changed

src/components/views/messages/MAudioBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class MAudioBody extends React.PureComponent<IBodyProps, IState>
9797
return (
9898
<span className="mx_MAudioBody">
9999
<AudioPlayer playback={this.state.playback} mediaName={this.props.mxEvent.getContent().body} />
100-
{/*<MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />*/}
100+
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }
101101
</span>
102102
);
103103
}

src/components/views/messages/MFileBody.tsx

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ limitations under the License.
1515
*/
1616

1717
import React, { createRef } from 'react';
18-
import PropTypes from 'prop-types';
1918
import filesize from 'filesize';
2019
import { _t } from '../../../languageHandler';
21-
import { decryptFile } from '../../../utils/DecryptFile';
2220
import Modal from '../../../Modal';
2321
import AccessibleButton from "../elements/AccessibleButton";
2422
import { replaceableComponent } from "../../../utils/replaceableComponent";
2523
import { mediaFromContent } from "../../../customisations/Media";
2624
import ErrorDialog from "../dialogs/ErrorDialog";
2725
import { TileShape } from "../rooms/EventTile";
28-
import { IContent, MatrixEvent } from "matrix-js-sdk/src";
29-
import { MediaEventHelper } from "../../../utils/MediaEventHelper";
26+
import { IContent } from "matrix-js-sdk/src";
3027
import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent";
3128
import { IBodyProps } from "./IBodyProps";
3229

@@ -181,6 +178,8 @@ export default class MFileBody extends React.Component<IProps, IState> {
181178
);
182179
}
183180

181+
const showDownloadLink = this.props.tileShape || !this.props.showGenericPlaceholder;
182+
184183
if (isEncrypted) {
185184
if (!this.state.decryptedBlob) {
186185
// Need to decrypt the attachment
@@ -205,12 +204,12 @@ export default class MFileBody extends React.Component<IProps, IState> {
205204
// but it is not guaranteed between various browsers' settings.
206205
return (
207206
<span className="mx_MFileBody">
208-
{placeholder}
209-
<div className="mx_MFileBody_download">
207+
{ placeholder }
208+
{ showDownloadLink && <div className="mx_MFileBody_download">
210209
<AccessibleButton onClick={decrypt}>
211210
{ _t("Decrypt %(text)s", { text: text }) }
212211
</AccessibleButton>
213-
</div>
212+
</div> }
214213
</span>
215214
);
216215
}
@@ -237,8 +236,8 @@ export default class MFileBody extends React.Component<IProps, IState> {
237236
// If the attachment is encrypted then put the link inside an iframe.
238237
return (
239238
<span className="mx_MFileBody">
240-
{placeholder}
241-
<div className="mx_MFileBody_download">
239+
{ placeholder }
240+
{ showDownloadLink && <div className="mx_MFileBody_download">
242241
<div style={{ display: "none" }}>
243242
{ /*
244243
* Add dummy copy of the "a" tag
@@ -252,7 +251,7 @@ export default class MFileBody extends React.Component<IProps, IState> {
252251
onLoad={onIframeLoad}
253252
ref={this.iframe}
254253
sandbox="allow-scripts allow-downloads allow-downloads-without-user-activation" />
255-
</div>
254+
</div> }
256255
</span>
257256
);
258257
} else if (contentUrl) {
@@ -300,40 +299,24 @@ export default class MFileBody extends React.Component<IProps, IState> {
300299
downloadProps["download"] = fileName;
301300
}
302301

303-
// If the attachment is not encrypted then we check whether we
304-
// are being displayed in the room timeline or in a list of
305-
// files in the right hand side of the screen.
306-
if (this.props.tileShape === TileShape.FileGrid) {
307-
return (
308-
<span className="mx_MFileBody">
309-
{placeholder}
310-
<div className="mx_MFileBody_download">
311-
<a className="mx_MFileBody_downloadLink" {...downloadProps}>
312-
{ fileName }
313-
</a>
314-
<div className="mx_MImageBody_size">
315-
{ content.info && content.info.size ? filesize(content.info.size) : "" }
316-
</div>
317-
</div>
318-
</span>
319-
);
320-
} else {
321-
return (
322-
<span className="mx_MFileBody">
323-
{placeholder}
324-
<div className="mx_MFileBody_download">
325-
<a {...downloadProps}>
326-
<span className="mx_MFileBody_download_icon" />
327-
{ _t("Download %(text)s", { text: text }) }
328-
</a>
329-
</div>
330-
</span>
331-
);
332-
}
302+
return (
303+
<span className="mx_MFileBody">
304+
{ placeholder }
305+
{ showDownloadLink && <div className="mx_MFileBody_download">
306+
<a {...downloadProps}>
307+
<span className="mx_MFileBody_download_icon" />
308+
{ _t("Download %(text)s", { text: text }) }
309+
</a>
310+
{ this.props.tileShape === TileShape.FileGrid && <div className="mx_MImageBody_size">
311+
{ content.info && content.info.size ? filesize(content.info.size) : "" }
312+
</div>}
313+
</div> }
314+
</span>
315+
);
333316
} else {
334317
const extra = text ? (': ' + text) : '';
335318
return <span className="mx_MFileBody">
336-
{placeholder}
319+
{ placeholder }
337320
{ _t("Invalid file%(extra)s", { extra: extra }) }
338321
</span>;
339322
}

src/components/views/messages/MImageBody.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
415415

416416
// Overidden by MStickerBody
417417
protected getFileBody(): JSX.Element {
418-
return <MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />;
418+
// We only ever need the download bar if we're appearing outside of the timeline
419+
if (this.props.tileShape) {
420+
return <MFileBody {...this.props} showGenericPlaceholder={false} />;
421+
}
419422
}
420423

421424
render() {

src/components/views/messages/MVideoBody.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { mediaFromContent } from "../../../customisations/Media";
2525
import { BLURHASH_FIELD } from "../../../ContentMessages";
2626
import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent";
2727
import { IBodyProps } from "./IBodyProps";
28+
import MFileBody from "./MFileBody";
2829

2930
interface IState {
3031
decryptedUrl?: string;
@@ -268,7 +269,7 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState>
268269
onPlay={this.videoOnPlay}
269270
>
270271
</video>
271-
{/*<MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />*/}
272+
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }
272273
</span>
273274
);
274275
}

src/components/views/messages/MVoiceMessageBody.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import InlineSpinner from '../elements/InlineSpinner';
2020
import { _t } from "../../../languageHandler";
2121
import RecordingPlayback from "../audio_messages/RecordingPlayback";
2222
import MAudioBody from "./MAudioBody";
23+
import MFileBody from "./MFileBody";
2324

2425
@replaceableComponent("views.messages.MVoiceMessageBody")
2526
export default class MVoiceMessageBody extends MAudioBody {
@@ -50,7 +51,7 @@ export default class MVoiceMessageBody extends MAudioBody {
5051
return (
5152
<span className="mx_MVoiceMessageBody">
5253
<RecordingPlayback playback={this.state.playback} tileShape={this.props.tileShape} />
53-
{/*<MFileBody {...this.props} decryptedBlob={this.state.decryptedBlob} showGenericPlaceholder={false} />*/}
54+
{ this.props.tileShape && <MFileBody {...this.props} showGenericPlaceholder={false} /> }
5455
</span>
5556
);
5657
}

0 commit comments

Comments
 (0)