@@ -15,18 +15,15 @@ limitations under the License.
1515*/
1616
1717import React , { createRef } from 'react' ;
18- import PropTypes from 'prop-types' ;
1918import filesize from 'filesize' ;
2019import { _t } from '../../../languageHandler' ;
21- import { decryptFile } from '../../../utils/DecryptFile' ;
2220import Modal from '../../../Modal' ;
2321import AccessibleButton from "../elements/AccessibleButton" ;
2422import { replaceableComponent } from "../../../utils/replaceableComponent" ;
2523import { mediaFromContent } from "../../../customisations/Media" ;
2624import ErrorDialog from "../dialogs/ErrorDialog" ;
2725import { 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" ;
3027import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent" ;
3128import { 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 }
0 commit comments