mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 10:19:08 +00:00
Refactor getFile and getFiles
Lint them using ESLint.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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();
|
this.clearForm();
|
||||||
return Promise.all(promises);
|
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;
|
|
||||||
}
|
}
|
||||||
return this.autoScale(file).then(this.readFile).then(function(attachment) {
|
const attachmentFlags = this.isVoiceNote ?
|
||||||
|
textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE :
|
||||||
|
null;
|
||||||
|
|
||||||
|
const setFlags = flags => (attachment) => {
|
||||||
|
const newAttachment = Object.assign({}, attachment);
|
||||||
if (flags) {
|
if (flags) {
|
||||||
attachment.flags = flags;
|
newAttachment.flags = flags;
|
||||||
}
|
}
|
||||||
return attachment;
|
return newAttachment;
|
||||||
}.bind(this));
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user