Fix codacy issues

pull/5366/head
Marcelo Schmidt 8 years ago
parent 8249b96d58
commit 2adfbf29fa
No known key found for this signature in database
GPG Key ID: CA48C21A7B66097E
  1. 12
      packages/rocketchat-custom-sounds/admin/adminSounds.js
  2. 16
      packages/rocketchat-custom-sounds/admin/soundEdit.js
  3. 18
      packages/rocketchat-custom-sounds/admin/soundInfo.js
  4. 4
      packages/rocketchat-custom-sounds/client/lib/CustomSounds.js
  5. 6
      packages/rocketchat-custom-sounds/server/methods/insertOrUpdateSound.js
  6. 6
      packages/rocketchat-custom-sounds/server/methods/uploadCustomSound.js
  7. 6
      packages/rocketchat-custom-sounds/server/models/CustomSounds.js
  8. 6
      packages/rocketchat-custom-sounds/server/publications/customSounds.js
  9. 8
      packages/rocketchat-custom-sounds/server/startup/custom-sounds.js
  10. 8
      packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js
  11. 2
      server/publications/subscription.js

@ -33,7 +33,7 @@ Template.adminSounds.helpers({
}); });
Template.adminSounds.onCreated(function() { Template.adminSounds.onCreated(function() {
let instance = this; const instance = this;
this.limit = new ReactiveVar(50); this.limit = new ReactiveVar(50);
this.filter = new ReactiveVar(''); this.filter = new ReactiveVar('');
this.ready = new ReactiveVar(false); this.ready = new ReactiveVar(false);
@ -61,22 +61,22 @@ Template.adminSounds.onCreated(function() {
}); });
this.autorun(function() { this.autorun(function() {
let limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0;
let subscription = instance.subscribe('customSounds', '', limit); const subscription = instance.subscribe('customSounds', '', limit);
instance.ready.set(subscription.ready()); instance.ready.set(subscription.ready());
}); });
this.customsounds = function() { this.customsounds = function() {
let filter = (isSetNotNull(() => instance.filter))? _.trim(instance.filter.get()) : ''; const filter = (isSetNotNull(() => instance.filter))? _.trim(instance.filter.get()) : '';
let query = {}; let query = {};
if (filter) { if (filter) {
let filterReg = new RegExp(s.escapeRegExp(filter), 'i'); const filterReg = new RegExp(s.escapeRegExp(filter), 'i');
query = { name: filterReg }; query = { name: filterReg };
} }
let limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0;
return RocketChat.models.CustomSounds.find(query, { limit: limit, sort: { name: 1 }}).fetch(); return RocketChat.models.CustomSounds.find(query, { limit: limit, sort: { name: 1 }}).fetch();
}; };

@ -25,7 +25,7 @@ Template.soundEdit.events({
}, },
['change input[type=file]'](ev) { ['change input[type=file]'](ev) {
let e = (isSetNotNull(() => ev.originalEvent)) ? ev.originalEvent : ev; const e = (isSetNotNull(() => ev.originalEvent)) ? ev.originalEvent : ev;
let files = e.target.files; let files = e.target.files;
if (!isSetNotNull(() => e.target.files) || files.length === 0) { if (!isSetNotNull(() => e.target.files) || files.length === 0) {
if (isSetNotNull(() => e.dataTransfer.files)) { if (isSetNotNull(() => e.dataTransfer.files)) {
@ -36,7 +36,7 @@ Template.soundEdit.events({
} }
//using let x of y here seems to have incompatibility with some phones //using let x of y here seems to have incompatibility with some phones
for (let file in files) { for (const file in files) {
if (files.hasOwnProperty(file)) { if (files.hasOwnProperty(file)) {
Template.instance().soundFile = files[file]; Template.instance().soundFile = files[file];
} }
@ -61,7 +61,7 @@ Template.soundEdit.onCreated(function() {
}; };
this.getSoundData = () => { this.getSoundData = () => {
let soundData = {}; const soundData = {};
if (isSetNotNull(() => this.sound)) { if (isSetNotNull(() => this.sound)) {
soundData._id = this.sound._id; soundData._id = this.sound._id;
soundData.previousName = this.sound.name; soundData.previousName = this.sound.name;
@ -74,9 +74,9 @@ Template.soundEdit.onCreated(function() {
}; };
this.validate = () => { this.validate = () => {
let soundData = this.getSoundData(); const soundData = this.getSoundData();
let errors = []; const errors = [];
if (!soundData.name) { if (!soundData.name) {
errors.push('Name'); errors.push('Name');
} }
@ -87,7 +87,7 @@ Template.soundEdit.onCreated(function() {
} }
} }
for (let error of errors) { for (const error of errors) {
toastr.error(TAPi18n.__('error-the-field-is-required', { field: TAPi18n.__(error) })); toastr.error(TAPi18n.__('error-the-field-is-required', { field: TAPi18n.__(error) }));
} }
@ -103,7 +103,7 @@ Template.soundEdit.onCreated(function() {
this.save = (form) => { this.save = (form) => {
if (this.validate()) { if (this.validate()) {
let soundData = this.getSoundData(); const soundData = this.getSoundData();
if (this.soundFile) { if (this.soundFile) {
soundData.newFile = true; soundData.newFile = true;
@ -119,7 +119,7 @@ Template.soundEdit.onCreated(function() {
if (this.soundFile) { if (this.soundFile) {
toastr.info(TAPi18n.__('Uploading_file')); toastr.info(TAPi18n.__('Uploading_file'));
let reader = new FileReader(); const reader = new FileReader();
reader.readAsBinaryString(this.soundFile); reader.readAsBinaryString(this.soundFile);
reader.onloadend = () => { reader.onloadend = () => {
Meteor.call('uploadCustomSound', reader.result, this.soundFile.type, soundData, (uploadError/*, data*/) => { Meteor.call('uploadCustomSound', reader.result, this.soundFile.type, soundData, (uploadError/*, data*/) => {

@ -1,7 +1,7 @@
/* globals isSetNotNull */ /* globals isSetNotNull */
Template.soundInfo.helpers({ Template.soundInfo.helpers({
name() { name() {
let sound = Template.instance().sound.get(); const sound = Template.instance().sound.get();
return sound.name; return sound.name;
}, },
@ -14,14 +14,14 @@ Template.soundInfo.helpers({
}, },
soundToEdit() { soundToEdit() {
let instance = Template.instance(); const instance = Template.instance();
return { return {
sound: instance.sound.get(), sound: instance.sound.get(),
back(name) { back(name) {
instance.editingSound.set(); instance.editingSound.set();
if (isSetNotNull(() => name)) { if (isSetNotNull(() => name)) {
let sound = instance.sound.get(); const sound = instance.sound.get();
if (isSetNotNull(() => sound.name) && sound.name !== name) { if (isSetNotNull(() => sound.name) && sound.name !== name) {
return instance.loadedName.set(name); return instance.loadedName.set(name);
} }
@ -35,9 +35,9 @@ Template.soundInfo.events({
['click .delete'](e, instance) { ['click .delete'](e, instance) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
let sound = instance.sound.get(); const sound = instance.sound.get();
if (isSetNotNull(() => sound)) { if (isSetNotNull(() => sound)) {
let _id = sound._id; const _id = sound._id;
swal({ swal({
title: t('Are_you_sure'), title: t('Are_you_sure'),
text: t('Custom_Sound_Delete_Warning'), text: t('Custom_Sound_Delete_Warning'),
@ -88,15 +88,15 @@ Template.soundInfo.onCreated(function() {
this.loadedName = new ReactiveVar(); this.loadedName = new ReactiveVar();
this.autorun(() => { this.autorun(() => {
let data = Template.currentData(); const data = Template.currentData();
if (isSetNotNull(() => data.clear)) { if (isSetNotNull(() => data.clear)) {
this.clear = data.clear; this.clear = data.clear;
} }
}); });
this.autorun(() => { this.autorun(() => {
let data = Template.currentData(); const data = Template.currentData();
let sound = this.sound.get(); const sound = this.sound.get();
if (isSetNotNull(() => sound.name)) { if (isSetNotNull(() => sound.name)) {
this.loadedName.set(sound.name); this.loadedName.set(sound.name);
} else if (isSetNotNull(() => data.name)) { } else if (isSetNotNull(() => data.name)) {
@ -105,7 +105,7 @@ Template.soundInfo.onCreated(function() {
}); });
this.autorun(() => { this.autorun(() => {
let data = Template.currentData(); const data = Template.currentData();
this.sound.set(data); this.sound.set(data);
}); });
}); });

@ -43,7 +43,7 @@ class CustomSounds {
} }
getURL(sound) { getURL(sound) {
let path = (Meteor.isCordova) ? Meteor.absoluteUrl().replace(/\/$/, '') : __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || ''; const path = (Meteor.isCordova) ? Meteor.absoluteUrl().replace(/\/$/, '') : __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || '';
return `${path}/custom-sounds/${sound._id}.${sound.extension}?_dc=${sound.random || 0}`; return `${path}/custom-sounds/${sound._id}.${sound.extension}?_dc=${sound.random || 0}`;
} }
@ -57,7 +57,7 @@ RocketChat.CustomSounds = new CustomSounds;
Meteor.startup(() => Meteor.startup(() =>
Meteor.call('listCustomSounds', (error, result) => { Meteor.call('listCustomSounds', (error, result) => {
for (let sound of result) { for (const sound of result) {
RocketChat.CustomSounds.add(sound); RocketChat.CustomSounds.add(sound);
} }
}) })

@ -13,7 +13,7 @@ Meteor.methods({
//allow all characters except colon, whitespace, comma, >, <, &, ", ', /, \, (, ) //allow all characters except colon, whitespace, comma, >, <, &, ", ', /, \, (, )
//more practical than allowing specific sets of characters; also allows foreign languages //more practical than allowing specific sets of characters; also allows foreign languages
let nameValidation = /[\s,:><&"'\/\\\(\)]/; const nameValidation = /[\s,:><&"'\/\\\(\)]/;
//silently strip colon; this allows for uploading :soundname: as soundname //silently strip colon; this allows for uploading :soundname: as soundname
soundData.name = soundData.name.replace(/:/g, ''); soundData.name = soundData.name.replace(/:/g, '');
@ -36,12 +36,12 @@ Meteor.methods({
if (!soundData._id) { if (!soundData._id) {
//insert sound //insert sound
let createSound = { const createSound = {
name: soundData.name, name: soundData.name,
extension: soundData.extension extension: soundData.extension
}; };
let _id = RocketChat.models.CustomSounds.create(createSound); const _id = RocketChat.models.CustomSounds.create(createSound);
createSound._id = _id; createSound._id = _id;
return _id; return _id;

@ -5,11 +5,11 @@ Meteor.methods({
throw new Meteor.Error('not_authorized'); throw new Meteor.Error('not_authorized');
} }
let file = new Buffer(binaryContent, 'binary'); const file = new Buffer(binaryContent, 'binary');
let rs = RocketChatFile.bufferToStream(file); const rs = RocketChatFile.bufferToStream(file);
RocketChatFileCustomSoundsInstance.deleteFile(`${soundData._id}.${soundData.extension}`); RocketChatFileCustomSoundsInstance.deleteFile(`${soundData._id}.${soundData.extension}`);
let ws = RocketChatFileCustomSoundsInstance.createWriteStream(`${soundData._id}.${soundData.extension}`, contentType); const ws = RocketChatFileCustomSoundsInstance.createWriteStream(`${soundData._id}.${soundData.extension}`, contentType);
ws.on('end', Meteor.bindEnvironment(() => ws.on('end', Meteor.bindEnvironment(() =>
Meteor.setTimeout(() => RocketChat.Notifications.notifyAll('updateCustomSound', {soundData}) Meteor.setTimeout(() => RocketChat.Notifications.notifyAll('updateCustomSound', {soundData})
, 500) , 500)

@ -12,7 +12,7 @@ class CustomSounds extends RocketChat.models._Base {
//find //find
findByName(name, options) { findByName(name, options) {
let query = { const query = {
name name
}; };
@ -20,7 +20,7 @@ class CustomSounds extends RocketChat.models._Base {
} }
findByNameExceptID(name, except, options) { findByNameExceptID(name, except, options) {
let query = { const query = {
_id: { $nin: [ except ] }, _id: { $nin: [ except ] },
name name
}; };
@ -30,7 +30,7 @@ class CustomSounds extends RocketChat.models._Base {
//update //update
setName(_id, name) { setName(_id, name) {
let update = { const update = {
$set: { $set: {
name name
} }

@ -3,21 +3,21 @@ Meteor.publish('customSounds', function(filter, limit) {
return this.ready(); return this.ready();
} }
let fields = { const fields = {
name: 1, name: 1,
extension: 1 extension: 1
}; };
filter = s.trim(filter); filter = s.trim(filter);
let options = { const options = {
fields, fields,
limit, limit,
sort: { name: 1 } sort: { name: 1 }
}; };
if (filter) { if (filter) {
let filterReg = new RegExp(s.escapeRegExp(filter), 'i'); const filterReg = new RegExp(s.escapeRegExp(filter), 'i');
return RocketChat.models.CustomSounds.findByName(filterReg, options); return RocketChat.models.CustomSounds.findByName(filterReg, options);
} }

@ -6,7 +6,7 @@ Meteor.startup(function() {
storeType = RocketChat.settings.get('CustomSounds_Storage_Type'); storeType = RocketChat.settings.get('CustomSounds_Storage_Type');
} }
let RocketChatStore = RocketChatFile[storeType]; const RocketChatStore = RocketChatFile[storeType];
if (!isSetNotNull(() => RocketChatStore)) { if (!isSetNotNull(() => RocketChatStore)) {
throw new Error(`Invalid RocketChatStore type [${storeType}]`); throw new Error(`Invalid RocketChatStore type [${storeType}]`);
@ -29,7 +29,7 @@ Meteor.startup(function() {
self = this; self = this;
return WebApp.connectHandlers.use('/custom-sounds/', Meteor.bindEnvironment(function(req, res/*, next*/) { return WebApp.connectHandlers.use('/custom-sounds/', Meteor.bindEnvironment(function(req, res/*, next*/) {
let params = const params =
{ sound: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')) }; { sound: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')) };
if (_.isEmpty(params.sound)) { if (_.isEmpty(params.sound)) {
@ -39,7 +39,7 @@ Meteor.startup(function() {
return; return;
} }
let file = RocketChatFileCustomSoundsInstance.getFileWithReadStream(params.sound); const file = RocketChatFileCustomSoundsInstance.getFileWithReadStream(params.sound);
if (!file) { if (!file) {
return; return;
} }
@ -51,7 +51,7 @@ Meteor.startup(function() {
fileUploadDate = file.uploadDate.toUTCString(); fileUploadDate = file.uploadDate.toUTCString();
} }
let reqModifiedHeader = req.headers['if-modified-since']; const reqModifiedHeader = req.headers['if-modified-since'];
if (isSetNotNull(() => reqModifiedHeader)) { if (isSetNotNull(() => reqModifiedHeader)) {
if (reqModifiedHeader === fileUploadDate) { if (reqModifiedHeader === fileUploadDate) {
res.setHeader('Last-Modified', reqModifiedHeader); res.setHeader('Last-Modified', reqModifiedHeader);

@ -231,14 +231,14 @@ Template.pushNotificationsFlexTab.events({
e.preventDefault(); e.preventDefault();
let audio = $(e.currentTarget).data('play'); let audio = $(e.currentTarget).data('play');
if (audio && audio !== 'none') { if (audio && audio !== 'none') {
let $audio = $('audio#' + audio); const $audio = $('audio#' + audio);
if ($audio && $audio[0] && $audio[0].play) { if ($audio && $audio[0] && $audio[0].play) {
$audio[0].play(); $audio[0].play();
} }
} else { } else {
audio = Meteor.user() && Meteor.user().settings && Meteor.user().settings.preferences && Meteor.user().settings.preferences.newMessageNotification || 'chime'; audio = Meteor.user() && Meteor.user().settings && Meteor.user().settings.preferences && Meteor.user().settings.preferences.newMessageNotification || 'chime';
if (audio && audio !== 'none') { if (audio && audio !== 'none') {
let $audio = $('audio#' + audio); const $audio = $('audio#' + audio);
if ($audio && $audio[0] && $audio[0].play) { if ($audio && $audio[0] && $audio[0].play) {
$audio[0].play(); $audio[0].play();
} }
@ -248,9 +248,9 @@ Template.pushNotificationsFlexTab.events({
'change select[name=audioNotification]'(e) { 'change select[name=audioNotification]'(e) {
e.preventDefault(); e.preventDefault();
let audio = $(e.currentTarget).val(); const audio = $(e.currentTarget).val();
if (audio && audio !== 'none') { if (audio && audio !== 'none') {
let $audio = $('audio#' + audio); const $audio = $('audio#' + audio);
if ($audio && $audio[0] && $audio[0].play) { if ($audio && $audio[0] && $audio[0].play) {
$audio[0].play(); $audio[0].play();
} }

@ -12,7 +12,7 @@ const fields = {
roles: 1, roles: 1,
unread: 1, unread: 1,
archived: 1, archived: 1,
audioNotification: 1 audioNotification: 1,
desktopNotifications: 1, desktopNotifications: 1,
desktopNotificationDuration: 1, desktopNotificationDuration: 1,
mobilePushNotifications: 1, mobilePushNotifications: 1,

Loading…
Cancel
Save