Multiple images can now be selected in file chooser and drag/drop

pull/148/head
Scott Nonnenberg 6 years ago
parent 7775ab8214
commit 0ba25ff8d5

@ -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": { "oneNonImageAtATimeToast": {
"message": "message":
"When including a non-image attachment, the limit is one attachment per message.", "When including a non-image attachment, the limit is one attachment per message.",

@ -132,7 +132,7 @@
</div> </div>
<div class='choose-file'> <div class='choose-file'>
<button class='paperclip thumbnail'></button> <button class='paperclip thumbnail'></button>
<input type='file' class='file-input'> <input type='file' class='file-input' multiple='multiple'>
</div> </div>
</div> </div>
</form> </form>

@ -288,9 +288,15 @@
}, },
async onChoseAttachment() { async onChoseAttachment() {
const fileField = this.$('input.file-input'); const fileField = this.$('input.file-input');
const file = fileField.prop('files')[0]; const files = fileField.prop('files');
await this.fileInput.maybeAddAttachment(file);
this.toggleMicrophone(); 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); fileField.val(null);
}, },

@ -42,9 +42,6 @@
Whisper.MaxAttachmentsToast = Whisper.ToastView.extend({ Whisper.MaxAttachmentsToast = Whisper.ToastView.extend({
template: i18n('maximumAttachments'), template: i18n('maximumAttachments'),
}); });
Whisper.MaxOneAttachmentToast = Whisper.ToastView.extend({
template: i18n('maxOneAttachmentToast'),
});
Whisper.FileInputView = Backbone.View.extend({ Whisper.FileInputView = Backbone.View.extend({
tagName: 'span', tagName: 'span',
@ -155,7 +152,7 @@
this.$el.removeClass('dropoff'); this.$el.removeClass('dropoff');
}, },
onDrop(e) { async onDrop(e) {
if (e.originalEvent.dataTransfer.types[0] !== 'Files') { if (e.originalEvent.dataTransfer.types[0] !== 'Files') {
return; return;
} }
@ -163,9 +160,13 @@
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
// eslint-disable-next-line prefer-destructuring const { files } = e.originalEvent.dataTransfer;
const file = e.originalEvent.dataTransfer.files[0]; for (let i = 0, max = files.length; i < max; i += 1) {
this.maybeAddAttachment(file); const file = files[i];
// eslint-disable-next-line no-await-in-loop
await this.maybeAddAttachment(file);
}
this.$el.removeClass('dropoff'); this.$el.removeClass('dropoff');
}, },
@ -255,12 +256,6 @@
toast.render(); toast.render();
}, },
showMaxOneAttachmentError() {
const toast = new Whisper.MaxOneAttachmentToast();
toast.$el.insertAfter(this.$el);
toast.render();
},
// Housekeeping // Housekeeping
addAttachment(attachment) { addAttachment(attachment) {
@ -280,12 +275,6 @@
const fileName = file.name; const fileName = file.name;
const contentType = file.type; 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)) { if (window.Signal.Util.isFileDangerous(fileName)) {
this.showDangerousError(); this.showDangerousError();
return; return;

Loading…
Cancel
Save