From 1e4b562922331d1b9aa0c273e605eae7a9f9eb0e Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 16 Jan 2019 10:32:57 -0800 Subject: [PATCH] Multiple images can now be selected in file chooser and drag/drop --- _locales/en/messages.json | 5 ----- background.html | 2 +- js/views/conversation_view.js | 12 +++++++++--- js/views/file_input_view.js | 27 ++++++++------------------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index b2c390a81..b4689a941 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -561,11 +561,6 @@ } } }, - "maxOneAttachmentToast": { - "message": "The limit is one attachment per message.", - "description": - "An error popup when the user has attempted to add an attachment" - }, "oneNonImageAtATimeToast": { "message": "When including a non-image attachment, the limit is one attachment per message.", diff --git a/background.html b/background.html index 64ef85855..0314dde5d 100644 --- a/background.html +++ b/background.html @@ -132,7 +132,7 @@
- +
diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 267b90d66..dfbfd11cc 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -288,9 +288,15 @@ }, async onChoseAttachment() { const fileField = this.$('input.file-input'); - const file = fileField.prop('files')[0]; - await this.fileInput.maybeAddAttachment(file); - this.toggleMicrophone(); + const files = fileField.prop('files'); + + for (let i = 0, max = files.length; i < max; i += 1) { + const file = files[i]; + // eslint-disable-next-line no-await-in-loop + await this.fileInput.maybeAddAttachment(file); + this.toggleMicrophone(); + } + fileField.val(null); }, diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index cebca04c7..0251c2283 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -42,9 +42,6 @@ Whisper.MaxAttachmentsToast = Whisper.ToastView.extend({ template: i18n('maximumAttachments'), }); - Whisper.MaxOneAttachmentToast = Whisper.ToastView.extend({ - template: i18n('maxOneAttachmentToast'), - }); Whisper.FileInputView = Backbone.View.extend({ tagName: 'span', @@ -155,7 +152,7 @@ this.$el.removeClass('dropoff'); }, - onDrop(e) { + async onDrop(e) { if (e.originalEvent.dataTransfer.types[0] !== 'Files') { return; } @@ -163,9 +160,13 @@ e.stopPropagation(); e.preventDefault(); - // eslint-disable-next-line prefer-destructuring - const file = e.originalEvent.dataTransfer.files[0]; - this.maybeAddAttachment(file); + const { files } = e.originalEvent.dataTransfer; + for (let i = 0, max = files.length; i < max; i += 1) { + const file = files[i]; + // eslint-disable-next-line no-await-in-loop + await this.maybeAddAttachment(file); + } + this.$el.removeClass('dropoff'); }, @@ -255,12 +256,6 @@ toast.render(); }, - showMaxOneAttachmentError() { - const toast = new Whisper.MaxOneAttachmentToast(); - toast.$el.insertAfter(this.$el); - toast.render(); - }, - // Housekeeping addAttachment(attachment) { @@ -280,12 +275,6 @@ const fileName = file.name; const contentType = file.type; - // TODO: remove this when clients are ready to remove multiple image attachments - // if (this.attachments.length > 0) { - // this.showMaxOneAttachmentError(); - // return; - // } - if (window.Signal.Util.isFileDangerous(fileName)) { this.showDangerousError(); return;