Save attachment button should download attachment if needed

This commit is contained in:
Fedor Indutny 2021-03-19 11:47:57 -07:00 committed by Josh Perez
parent 58cb9fba6b
commit d7ec22fb0b

View file

@ -796,20 +796,7 @@ export class Message extends React.PureComponent<Props, State> {
)} )}
// There's only ever one of these, so we don't want users to tab into it // There's only ever one of these, so we don't want users to tab into it
tabIndex={-1} tabIndex={-1}
onClick={(event: React.MouseEvent) => { onClick={this.openGenericAttachment}
event.stopPropagation();
event.preventDefault();
if (hasNotDownloaded(firstAttachment)) {
kickOffAttachmentDownload({
attachment: firstAttachment,
messageId: id,
});
return;
}
this.openGenericAttachment();
}}
> >
{pending ? ( {pending ? (
<div className="module-message__generic-attachment__spinner-container"> <div className="module-message__generic-attachment__spinner-container">
@ -2097,7 +2084,13 @@ export class Message extends React.PureComponent<Props, State> {
}; };
public openGenericAttachment = (event?: React.MouseEvent): void => { public openGenericAttachment = (event?: React.MouseEvent): void => {
const { attachments, downloadAttachment, timestamp } = this.props; const {
id,
attachments,
downloadAttachment,
timestamp,
kickOffAttachmentDownload,
} = this.props;
if (event) { if (event) {
event.preventDefault(); event.preventDefault();
@ -2109,6 +2102,14 @@ export class Message extends React.PureComponent<Props, State> {
} }
const attachment = attachments[0]; const attachment = attachments[0];
if (hasNotDownloaded(attachment)) {
kickOffAttachmentDownload({
attachment,
messageId: id,
});
return;
}
const { fileName } = attachment; const { fileName } = attachment;
const isDangerous = isFileDangerous(fileName || ''); const isDangerous = isFileDangerous(fileName || '');