Skip to content

Commit

Permalink
Attachment-add flow: capture renamed filename, file type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Sep 18, 2019
1 parent 3719724 commit 344e7e5
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions js/views/conversation_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@
return;
}

this.addAttachment(attachment);
await this.addAttachment(attachment);
},

isSizeOkay(attachment) {
Expand Down Expand Up @@ -1256,37 +1256,45 @@
if (MIME.isJPEG(file.type)) {
const rotatedDataUrl = await window.autoOrientImage(file);
const rotatedBlob = VisualAttachment.dataURLToBlobSync(rotatedDataUrl);
const { contentType, file: resizedBlob } = await this.autoScale({
const {
contentType,
file: resizedBlob,
fileName,
} = await this.autoScale({
contentType: file.type,
rotatedBlob,
fileName: file.name,
file: rotatedBlob,
});
const data = await await VisualAttachment.blobToArrayBuffer(
resizedBlob
);

return {
fileName: file.name,
fileName: fileName || file.name,
contentType,
data,
size: data.byteLength,
};
}

const { contentType, file: resizedBlob } = await this.autoScale({
contentType: file.type,
file,
});
const { contentType, file: resizedBlob, fileName } = await this.autoScale(
{
contentType: file.type,
fileName: file.name,
file,
}
);
const data = await await VisualAttachment.blobToArrayBuffer(resizedBlob);
return {
fileName: file.name,
fileName: fileName || file.name,
contentType,
data,
size: data.byteLength,
};
},

autoScale(attachment) {
const { contentType, file } = attachment;
const { contentType, file, fileName } = attachment;
if (
contentType.split('/')[0] !== 'image' ||
contentType === 'image/tiff'
Expand Down Expand Up @@ -1351,7 +1359,7 @@

resolve({
...attachment,
fileName: this.fixExtension(attachment.fileName, targetContentType),
fileName: this.fixExtension(fileName, targetContentType),
contentType: targetContentType,
file: blob,
});
Expand Down

0 comments on commit 344e7e5

Please sign in to comment.