Refactor getFile and getFiles

Lint them using ESLint.
This commit is contained in:
Daniel Gasienica
2018-02-13 12:21:42 -05:00
parent 07e9114e65
commit a4582ae2fb
2 changed files with 38 additions and 23 deletions

View File

@@ -16,5 +16,6 @@ test/views/*.js
# ES2015+ files # ES2015+ files
!js/background.js !js/background.js
!js/views/file_input_view.js
!main.js !main.js
!prepare_build.js !prepare_build.js

View File

@@ -1,3 +1,7 @@
/* eslint-disable */
/* global textsecure: false */
/* /*
* vim: ts=4:sw=4:expandtab * vim: ts=4:sw=4:expandtab
*/ */
@@ -180,30 +184,40 @@
return files && files.length && files.length > 0; return files && files.length && files.length > 0;
}, },
getFiles: function() { /* eslint-enable */
var promises = []; /* jshint ignore:start */
var files = this.file ? [this.file] : this.$input.prop('files'); getFiles() {
for (var i = 0; i < files.length; i++) { const files = this.file ? [this.file] : this.$input.prop('files');
promises.push(this.getFile(files[i])); const promises = Promise.all(
} files.map(file => this.getFile(file))
this.clearForm(); );
return Promise.all(promises); this.clearForm();
}, return promises;
},
getFile: function(file) { getFile(rawFile) {
file = file || this.file || this.$input.prop('files')[0]; const file = rawFile || this.file || this.$input.prop('files')[0];
if (file === undefined) { return Promise.resolve(); } if (file === undefined) {
var flags; return Promise.resolve();
if (this.isVoiceNote) { }
flags = textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE; const attachmentFlags = this.isVoiceNote ?
} textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE :
return this.autoScale(file).then(this.readFile).then(function(attachment) { null;
if (flags) {
attachment.flags = flags; const setFlags = flags => (attachment) => {
} const newAttachment = Object.assign({}, attachment);
return attachment; if (flags) {
}.bind(this)); newAttachment.flags = flags;
}, }
return newAttachment;
};
return this.autoScale(file)
.then(this.readFile)
.then(setFlags(attachmentFlags))
},
/* jshint ignore:end */
/* eslint-disable */
getThumbnail: function() { getThumbnail: function() {
// Scale and crop an image to 256px square // Scale and crop an image to 256px square