diff --git a/packages/rocketchat-custom-sounds/admin/adminSounds.js b/packages/rocketchat-custom-sounds/admin/adminSounds.js index 9138d477578..62386d22f6a 100644 --- a/packages/rocketchat-custom-sounds/admin/adminSounds.js +++ b/packages/rocketchat-custom-sounds/admin/adminSounds.js @@ -1,7 +1,7 @@ -/* globals isSetNotNull, RocketChatTabBar */ +/* globals RocketChatTabBar */ Template.adminSounds.helpers({ isReady() { - if (isSetNotNull(() => Template.instance().ready)) { + if (Template.instance().ready != null) { return Template.instance().ready.get(); } return undefined; @@ -10,14 +10,14 @@ Template.adminSounds.helpers({ return Template.instance().customsounds(); }, isLoading() { - if (isSetNotNull(() => Template.instance().ready)) { + if (Template.instance().ready != null) { if (!Template.instance().ready.get()) { return 'btn-loading'; } } }, hasMore() { - if (isSetNotNull(() => Template.instance().limit)) { + if (Template.instance().limit != null) { if (typeof Template.instance().customsounds === 'function') { return Template.instance().limit.get() === Template.instance().customsounds().length; } @@ -65,13 +65,13 @@ Template.adminSounds.onCreated(function() { }); this.autorun(function() { - const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; + const limit = (instance.limit != null) ? instance.limit.get() : 0; const subscription = instance.subscribe('customSounds', '', limit); instance.ready.set(subscription.ready()); }); this.customsounds = function() { - const filter = (isSetNotNull(() => instance.filter))? _.trim(instance.filter.get()) : ''; + const filter = (instance.filter != null) ? _.trim(instance.filter.get()) : ''; let query = {}; @@ -80,7 +80,7 @@ Template.adminSounds.onCreated(function() { query = { name: filterReg }; } - const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; + const limit = (instance.limit != null) ? instance.limit.get() : 0; return RocketChat.models.CustomSounds.find(query, { limit: limit, sort: { name: 1 }}).fetch(); }; diff --git a/packages/rocketchat-custom-sounds/admin/soundEdit.js b/packages/rocketchat-custom-sounds/admin/soundEdit.js index 0c9462394ca..bda3f53e18d 100644 --- a/packages/rocketchat-custom-sounds/admin/soundEdit.js +++ b/packages/rocketchat-custom-sounds/admin/soundEdit.js @@ -1,5 +1,5 @@ import toastr from 'toastr'; -/* globals isSetNotNull */ + Template.soundEdit.helpers({ sound() { return Template.instance().sound; @@ -25,10 +25,10 @@ Template.soundEdit.events({ }, 'change input[type=file]'(ev) { - const e = (isSetNotNull(() => ev.originalEvent)) ? ev.originalEvent : ev; + const e = (ev.originalEvent != null) ? ev.originalEvent : ev; let files = e.target.files; - if (!isSetNotNull(() => e.target.files) || files.length === 0) { - if (isSetNotNull(() => e.dataTransfer.files)) { + if (e.target.files == null || files.length === 0) { + if (e.dataTransfer.files != null) { files = e.dataTransfer.files; } else { files = []; @@ -45,7 +45,7 @@ Template.soundEdit.events({ }); Template.soundEdit.onCreated(function() { - if (isSetNotNull(() => this.data)) { + if (this.data != null) { this.sound = this.data.sound; } else { this.sound = undefined; @@ -62,7 +62,7 @@ Template.soundEdit.onCreated(function() { this.getSoundData = () => { const soundData = {}; - if (isSetNotNull(() => this.sound)) { + if (this.sound != null) { soundData._id = this.sound._id; soundData.previousName = this.sound.name; soundData.extension = this.sound.extension; diff --git a/packages/rocketchat-custom-sounds/admin/soundInfo.js b/packages/rocketchat-custom-sounds/admin/soundInfo.js index a7ee3e11d77..d02d367f07e 100644 --- a/packages/rocketchat-custom-sounds/admin/soundInfo.js +++ b/packages/rocketchat-custom-sounds/admin/soundInfo.js @@ -1,4 +1,3 @@ -/* globals isSetNotNull */ Template.soundInfo.helpers({ name() { const sound = Template.instance().sound.get(); @@ -22,9 +21,9 @@ Template.soundInfo.helpers({ back(name) { instance.editingSound.set(); - if (isSetNotNull(() => name)) { + if (name != null) { const sound = instance.sound.get(); - if (isSetNotNull(() => sound.name) && sound.name !== name) { + if (sound.name != null && sound.name !== name) { return instance.loadedName.set(name); } } @@ -38,7 +37,7 @@ Template.soundInfo.events({ e.stopPropagation(); e.preventDefault(); const sound = instance.sound.get(); - if (isSetNotNull(() => sound)) { + if (sound != null) { const _id = sound._id; swal({ title: t('Are_you_sure'), @@ -91,7 +90,7 @@ Template.soundInfo.onCreated(function() { this.autorun(() => { const data = Template.currentData(); - if (isSetNotNull(() => data.clear)) { + if (data.clear != null) { this.clear = data.clear; } }); @@ -99,9 +98,9 @@ Template.soundInfo.onCreated(function() { this.autorun(() => { const data = Template.currentData(); const sound = this.sound.get(); - if (isSetNotNull(() => sound.name)) { + if (sound.name != null) { this.loadedName.set(sound.name); - } else if (isSetNotNull(() => data.name)) { + } else if (data.name != null) { this.loadedName.set(data.name); } }); diff --git a/packages/rocketchat-custom-sounds/function-isSet.js b/packages/rocketchat-custom-sounds/function-isSet.js deleted file mode 100644 index 9bd663ba5c0..00000000000 --- a/packages/rocketchat-custom-sounds/function-isSet.js +++ /dev/null @@ -1,25 +0,0 @@ -/* globals isSet:true, isSetNotNull:true */ -//http://stackoverflow.com/a/26990347 function isSet() from Gajus -isSet = function(fn) { - var value; - try { - value = fn(); - } catch (e) { - value = undefined; - } finally { - return value !== undefined; - } -}; - -isSetNotNull = function(fn) { - var value; - try { - value = fn(); - } catch (e) { - value = null; - } finally { - return value !== null && value !== undefined; - } -}; - -/* exported isSet, isSetNotNull */ diff --git a/packages/rocketchat-custom-sounds/package.js b/packages/rocketchat-custom-sounds/package.js index 37fb34df9c8..7931efc269a 100644 --- a/packages/rocketchat-custom-sounds/package.js +++ b/packages/rocketchat-custom-sounds/package.js @@ -19,8 +19,6 @@ Package.onUse(function(api) { api.use('kadira:flow-router', 'client'); - api.addFiles('function-isSet.js'); - api.addFiles('server/startup/custom-sounds.js', 'server'); api.addFiles('server/startup/permissions.js', 'server'); api.addFiles('server/startup/settings.js', 'server'); diff --git a/packages/rocketchat-custom-sounds/server/methods/deleteCustomSound.js b/packages/rocketchat-custom-sounds/server/methods/deleteCustomSound.js index b63c7d03857..82d01933e02 100644 --- a/packages/rocketchat-custom-sounds/server/methods/deleteCustomSound.js +++ b/packages/rocketchat-custom-sounds/server/methods/deleteCustomSound.js @@ -1,4 +1,4 @@ -/* globals isSetNotNull, RocketChatFileCustomSoundsInstance */ +/* globals RocketChatFileCustomSoundsInstance */ Meteor.methods({ deleteCustomSound(_id) { let sound = null; @@ -9,7 +9,7 @@ Meteor.methods({ throw new Meteor.Error('not_authorized'); } - if (!isSetNotNull(() => sound)) { + if (sound == null) { throw new Meteor.Error('Custom_Sound_Error_Invalid_Sound', 'Invalid sound', { method: 'deleteCustomSound' }); } diff --git a/packages/rocketchat-custom-sounds/server/startup/custom-sounds.js b/packages/rocketchat-custom-sounds/server/startup/custom-sounds.js index e9141956668..2cc290603f6 100644 --- a/packages/rocketchat-custom-sounds/server/startup/custom-sounds.js +++ b/packages/rocketchat-custom-sounds/server/startup/custom-sounds.js @@ -1,4 +1,4 @@ -/* globals isSetNotNull, RocketChatFileCustomSoundsInstance */ +/* globals RocketChatFileCustomSoundsInstance */ Meteor.startup(function() { let storeType = 'GridFS'; @@ -8,14 +8,14 @@ Meteor.startup(function() { const RocketChatStore = RocketChatFile[storeType]; - if (!isSetNotNull(() => RocketChatStore)) { + if (RocketChatStore == null) { throw new Error(`Invalid RocketChatStore type [${storeType}]`); } console.log(`Using ${storeType} for custom sounds storage`.green); let path = '~/uploads'; - if (isSetNotNull(() => RocketChat.settings.get('CustomSounds_FileSystemPath'))) { + if (RocketChat.settings.get('CustomSounds_FileSystemPath') != null) { if (RocketChat.settings.get('CustomSounds_FileSystemPath').trim() !== '') { path = RocketChat.settings.get('CustomSounds_FileSystemPath'); } @@ -47,12 +47,12 @@ Meteor.startup(function() { res.setHeader('Content-Disposition', 'inline'); let fileUploadDate = undefined; - if (isSetNotNull(() => file.uploadDate)) { + if (file.uploadDate != null) { fileUploadDate = file.uploadDate.toUTCString(); } const reqModifiedHeader = req.headers['if-modified-since']; - if (isSetNotNull(() => reqModifiedHeader)) { + if (reqModifiedHeader != null) { if (reqModifiedHeader === fileUploadDate) { res.setHeader('Last-Modified', reqModifiedHeader); res.writeHead(304); @@ -63,7 +63,7 @@ Meteor.startup(function() { res.setHeader('Cache-Control', 'public, max-age=0'); res.setHeader('Expires', '-1'); - if (isSetNotNull(() => fileUploadDate)) { + if (fileUploadDate != null) { res.setHeader('Last-Modified', fileUploadDate); } else { res.setHeader('Last-Modified', new Date().toUTCString()); diff --git a/packages/rocketchat-emoji-custom/admin/adminEmoji.js b/packages/rocketchat-emoji-custom/admin/adminEmoji.js index 6fe0499ef6d..a1ddce4c9c5 100644 --- a/packages/rocketchat-emoji-custom/admin/adminEmoji.js +++ b/packages/rocketchat-emoji-custom/admin/adminEmoji.js @@ -1,7 +1,7 @@ -/* globals isSetNotNull, RocketChatTabBar */ +/* globals RocketChatTabBar */ Template.adminEmoji.helpers({ isReady() { - if (isSetNotNull(() => Template.instance().ready)) { + if (Template.instance().ready != null) { return Template.instance().ready.get(); } return undefined; @@ -10,14 +10,14 @@ Template.adminEmoji.helpers({ return Template.instance().customemoji(); }, isLoading() { - if (isSetNotNull(() => Template.instance().ready)) { + if (Template.instance().ready != null) { if (!Template.instance().ready.get()) { return 'btn-loading'; } } }, hasMore() { - if (isSetNotNull(() => Template.instance().limit)) { + if (Template.instance().limit != null) { if (typeof Template.instance().customemoji === 'function') { return Template.instance().limit.get() === Template.instance().customemoji().length; } @@ -61,13 +61,13 @@ Template.adminEmoji.onCreated(function() { }); this.autorun(function() { - const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; + const limit = (instance.limit != null) ? instance.limit.get() : 0; const subscription = instance.subscribe('fullEmojiData', '', limit); instance.ready.set(subscription.ready()); }); this.customemoji = function() { - const filter = (isSetNotNull(() => instance.filter))? _.trim(instance.filter.get()) : ''; + const filter = (instance.filter != null) ? _.trim(instance.filter.get()) : ''; let query = {}; @@ -76,7 +76,7 @@ Template.adminEmoji.onCreated(function() { query = { $or: [ { name: filterReg }, {aliases: filterReg } ] }; } - const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0; + const limit = (instance.limit != null) ? instance.limit.get() : 0; return RocketChat.models.EmojiCustom.find(query, { limit: limit, sort: { name: 1 }}).fetch(); }; diff --git a/packages/rocketchat-emoji-custom/admin/emojiEdit.js b/packages/rocketchat-emoji-custom/admin/emojiEdit.js index 0a40e09a18a..22177814881 100644 --- a/packages/rocketchat-emoji-custom/admin/emojiEdit.js +++ b/packages/rocketchat-emoji-custom/admin/emojiEdit.js @@ -1,5 +1,5 @@ import toastr from 'toastr'; -/* globals isSetNotNull */ + Template.emojiEdit.helpers({ emoji() { return Template.instance().emoji; @@ -25,10 +25,10 @@ Template.emojiEdit.events({ }, 'change input[type=file]'(ev) { - const e = (isSetNotNull(() => ev.originalEvent)) ? ev.originalEvent : ev; + const e = ev.originalEvent != null ? ev.originalEvent : ev; let files = e.target.files; - if (!isSetNotNull(() => e.target.files) || files.length === 0) { - if (isSetNotNull(() => e.dataTransfer.files)) { + if (files == null || files.length === 0) { + if (e.dataTransfer != null && e.dataTransfer.files != null) { files = e.dataTransfer.files; } else { files = []; @@ -45,7 +45,7 @@ Template.emojiEdit.events({ }); Template.emojiEdit.onCreated(function() { - if (isSetNotNull(() => this.data)) { + if (this.data != null) { this.emoji = this.data.emoji; } else { this.emoji = undefined; @@ -63,7 +63,7 @@ Template.emojiEdit.onCreated(function() { this.getEmojiData = () => { const emojiData = {}; - if (isSetNotNull(() => this.emoji)) { + if (this.emoji != null) { emojiData._id = this.emoji._id; emojiData.previousName = this.emoji.name; emojiData.extension = this.emoji.extension; diff --git a/packages/rocketchat-emoji-custom/admin/emojiInfo.js b/packages/rocketchat-emoji-custom/admin/emojiInfo.js index 68eaa4f90d2..f839c38312d 100644 --- a/packages/rocketchat-emoji-custom/admin/emojiInfo.js +++ b/packages/rocketchat-emoji-custom/admin/emojiInfo.js @@ -1,4 +1,3 @@ -/* globals isSetNotNull */ Template.emojiInfo.helpers({ name() { const emoji = Template.instance().emoji.get(); @@ -26,9 +25,9 @@ Template.emojiInfo.helpers({ back(name) { instance.editingEmoji.set(); - if (isSetNotNull(() => name)) { + if (name != null) { const emoji = instance.emoji.get(); - if (isSetNotNull(() => emoji.name) && emoji.name !== name) { + if (emoji != null && emoji.name != null && emoji.name !== name) { return instance.loadedName.set(name); } } @@ -46,7 +45,7 @@ Template.emojiInfo.events({ e.stopPropagation(); e.preventDefault(); const emoji = instance.emoji.get(); - if (isSetNotNull(() => emoji)) { + if (emoji != null) { const _id = emoji._id; swal({ title: t('Are_you_sure'), @@ -100,7 +99,7 @@ Template.emojiInfo.onCreated(function() { this.autorun(() => { const data = Template.currentData(); - if (isSetNotNull(() => data.clear)) { + if (data != null && data.clear != null) { this.clear = data.clear; } }); @@ -108,9 +107,9 @@ Template.emojiInfo.onCreated(function() { this.autorun(() => { const data = Template.currentData(); const emoji = this.emoji.get(); - if (isSetNotNull(() => emoji.name)) { + if (emoji != null && emoji.name != null) { this.loadedName.set(emoji.name); - } else if (isSetNotNull(() => data.name)) { + } else if (data != null && data.name != null) { this.loadedName.set(data.name); } }); diff --git a/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js b/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js index bcfebb41dd7..09269cac0eb 100644 --- a/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js +++ b/packages/rocketchat-emoji-custom/server/methods/deleteEmojiCustom.js @@ -1,4 +1,4 @@ -/* globals isSetNotNull, RocketChatFileEmojiCustomInstance */ +/* globals RocketChatFileEmojiCustomInstance */ Meteor.methods({ deleteEmojiCustom(emojiID) { let emoji = null; @@ -9,7 +9,7 @@ Meteor.methods({ throw new Meteor.Error('not_authorized'); } - if (!isSetNotNull(() => emoji)) { + if (emoji == null) { throw new Meteor.Error('Custom_Emoji_Error_Invalid_Emoji', 'Invalid emoji', { method: 'deleteEmojiCustom' }); } diff --git a/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js b/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js index 6003a31f954..a69e748c3ac 100644 --- a/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js +++ b/packages/rocketchat-emoji-custom/server/startup/emoji-custom.js @@ -1,4 +1,4 @@ -/* globals isSetNotNull, RocketChatFileEmojiCustomInstance */ +/* globals RocketChatFileEmojiCustomInstance */ Meteor.startup(function() { let storeType = 'GridFS'; @@ -8,14 +8,14 @@ Meteor.startup(function() { const RocketChatStore = RocketChatFile[storeType]; - if (!isSetNotNull(() => RocketChatStore)) { + if (RocketChatStore == null) { throw new Error(`Invalid RocketChatStore type [${storeType}]`); } console.log(`Using ${storeType} for custom emoji storage`.green); let path = '~/uploads'; - if (isSetNotNull(() => RocketChat.settings.get('EmojiUpload_FileSystemPath'))) { + if (RocketChat.settings.get('EmojiUpload_FileSystemPath') != null) { if (RocketChat.settings.get('EmojiUpload_FileSystemPath').trim() !== '') { path = RocketChat.settings.get('EmojiUpload_FileSystemPath'); } @@ -41,7 +41,7 @@ Meteor.startup(function() { res.setHeader('Content-Disposition', 'inline'); - if (!isSetNotNull(() => file)) { + if (file == null) { //use code from username initials renderer until file upload is complete res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', 'public, max-age=0'); @@ -73,12 +73,12 @@ Meteor.startup(function() { } let fileUploadDate = undefined; - if (isSetNotNull(() => file.uploadDate)) { + if (file.uploadDate != null) { fileUploadDate = file.uploadDate.toUTCString(); } const reqModifiedHeader = req.headers['if-modified-since']; - if (isSetNotNull(() => reqModifiedHeader)) { + if (reqModifiedHeader != null) { if (reqModifiedHeader === fileUploadDate) { res.setHeader('Last-Modified', reqModifiedHeader); res.writeHead(304); @@ -89,7 +89,7 @@ Meteor.startup(function() { res.setHeader('Cache-Control', 'public, max-age=0'); res.setHeader('Expires', '-1'); - if (isSetNotNull(() => fileUploadDate)) { + if (fileUploadDate != null) { res.setHeader('Last-Modified', fileUploadDate); } else { res.setHeader('Last-Modified', new Date().toUTCString());