Properly cancel image encoding

This commit is contained in:
Josh Perez 2021-08-20 16:33:06 -04:00 committed by GitHub
parent 70d059beeb
commit 0e2885a5a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1668,15 +1668,7 @@ Whisper.ConversationView = Whisper.View.extend({
const { files } = e.originalEvent.dataTransfer; const { files } = e.originalEvent.dataTransfer;
for (let i = 0, max = files.length; i < max; i += 1) { for (let i = 0, max = files.length; i < max; i += 1) {
const file = files[i]; const file = files[i];
try { this.maybeAddAttachment(file);
// eslint-disable-next-line no-await-in-loop
await this.maybeAddAttachment(file);
} catch (error) {
window.log.error(
'ConversationView/onDrop: Failed to add attachment:',
error && error.stack ? error.stack : error
);
}
} }
}, },
@ -1795,8 +1787,7 @@ Whisper.ConversationView = Whisper.View.extend({
const draftAttachments = (model.get('draftAttachments') || []).filter( const draftAttachments = (model.get('draftAttachments') || []).filter(
draftAttachment => draftAttachment =>
!draftAttachment.pending && !draftAttachment.pending &&
nodePath.parse(String(draftAttachment.fileName)).name !== draftAttachment.fileName !== attachment.fileName
attachment.fileName
); );
this.model.set({ this.model.set({
draftAttachments: [...draftAttachments, onDisk], draftAttachments: [...draftAttachments, onDisk],
@ -1944,12 +1935,10 @@ Whisper.ConversationView = Whisper.View.extend({
updateAttachmentsView() { updateAttachmentsView() {
const { model }: { model: ConversationModel } = this; const { model }: { model: ConversationModel } = this;
const draftAttachments = this.model.get('draftAttachments') || []; const draftAttachments = model.get('draftAttachments') || [];
window.reduxActions.composer.replaceAttachments( window.reduxActions.composer.replaceAttachments(
model.get('id'), model.get('id'),
draftAttachments.map((att: AttachmentType) => draftAttachments.map(att => this.resolveOnDiskAttachment(att))
this.resolveOnDiskAttachment(att)
)
); );
this.toggleMicrophone(); this.toggleMicrophone();
if (this.hasFiles()) { if (this.hasFiles()) {
@ -2029,13 +2018,15 @@ Whisper.ConversationView = Whisper.View.extend({
window.Signal.Util.GoogleChrome.isImageTypeSupported(fileType) || window.Signal.Util.GoogleChrome.isImageTypeSupported(fileType) ||
isHeic(fileType) isHeic(fileType)
) { ) {
const fileName = nodePath.parse(file.name).name;
// Add a pending attachment since transcoding may take a while // Add a pending attachment since transcoding may take a while
this.model.set({ this.model.set({
draftAttachments: [ draftAttachments: [
...draftAttachments, ...draftAttachments,
{ {
contentType: IMAGE_JPEG, contentType: IMAGE_JPEG,
fileName: nodePath.parse(file.name).name, fileName,
path: file.name,
pending: true, pending: true,
}, },
], ],
@ -2043,6 +2034,18 @@ Whisper.ConversationView = Whisper.View.extend({
this.updateAttachmentsView(); this.updateAttachmentsView();
attachment = await handleImageAttachment(file); attachment = await handleImageAttachment(file);
const hasDraftAttachmentPending = (
model.get('draftAttachments') || []
).some(
draftAttachment =>
draftAttachment.pending && draftAttachment.fileName === fileName
);
// User has canceled the draft so we don't need to continue processing
if (!hasDraftAttachmentPending) {
return;
}
} else if ( } else if (
window.Signal.Util.GoogleChrome.isVideoTypeSupported(fileType) window.Signal.Util.GoogleChrome.isVideoTypeSupported(fileType)
) { ) {