From 8d8fe8bb91bd1c5fc4e6c641ce89c767b87711b2 Mon Sep 17 00:00:00 2001 From: Thomas Kurz Date: Sun, 15 Apr 2018 19:57:40 +0200 Subject: [PATCH] #8381 removes underscore functions where it is possible (fixes https://github.com/RocketChat/Rocket.Chat/pull/10110#pullrequestreview-111213810) --- package-lock.json | 2 +- .../chatpal-search/server/provider/index.js | 65 ++++++++++--------- .../client/provider/result.js | 2 +- .../server/model/provider.js | 11 ++-- .../server/service/providerService.js | 19 +++--- .../server/service/validationService.js | 60 +++++++++-------- 6 files changed, 78 insertions(+), 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index 140c99548c68..fe310f200699 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Rocket.Chat", - "version": "0.63.0-rc.1", + "version": "0.64.0-develop", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/chatpal-search/server/provider/index.js b/packages/chatpal-search/server/provider/index.js index 3361cb7f064b..6dd6edad68f0 100644 --- a/packages/chatpal-search/server/provider/index.js +++ b/packages/chatpal-search/server/provider/index.js @@ -1,4 +1,3 @@ -import _ from 'underscore'; import ChatpalLogger from '../utils/logger'; import { Random } from 'meteor/random'; @@ -21,11 +20,10 @@ class Backend { index(docs) { const options = { data:docs, - params:{language:this._options.language} + params:{language:this._options.language}, + ...this._options.httpOptions }; - _.extend(options, this._options.httpOptions); - try { const response = HTTP.call('POST', `${ this._options.baseurl }${ this._options.updatepath }`, options); @@ -53,14 +51,15 @@ class Backend { remove(type, id) { ChatpalLogger.debug(`Remove ${ type }(${ id }) from Index`); - const options = {data:{ - delete: { - query: `id:${ id } AND type:${ type }` + const options = { + data:{ + delete: { + query: `id:${ id } AND type:${ type }` + }, + commit:{} }, - commit:{} - }}; - - _.extend(options, this._options.httpOptions); + ...this._options.httpOptions + }; try { const response = HTTP.call('POST', this._options.baseurl + this._options.clearpath, options); @@ -82,9 +81,10 @@ class Backend { */ query(params, callback) { - const options = {params}; - - _.extend(options, this._options.httpOptions); + const options = { + params, + ...this._options.httpOptions + }; ChatpalLogger.debug('query: ', JSON.stringify(options, null, 2)); @@ -113,9 +113,10 @@ class Backend { suggest(params, callback) { - const options = {params}; - - _.extend(options, this._options.httpOptions);console.log(options); + const options = { + params, + ...this._options.httpOptions + }; HTTP.call('POST', this._options.baseurl + this._options.suggestionpath, options, (err, result) => { if (err) { return callback(err); } @@ -131,14 +132,14 @@ class Backend { clear() { ChatpalLogger.debug('Clear Index'); - const options = {data:{ - delete: { - query: '*:*' - }, - commit:{} - }}; - - _.extend(options, this._options.httpOptions); + const options = { + data:{ + delete: { + query: '*:*' + }, + commit:{} + },...this._options.httpOptions + }; try { const response = HTTP.call('POST', this._options.baseurl + this._options.clearpath, options); @@ -159,11 +160,10 @@ class Backend { const options = { params: { stats:true - } + }, + ...config.httpOptions }; - _.extend(options, config.httpOptions); - try { const response = HTTP.call('GET', config.baseurl + config.pingpath, options); @@ -266,7 +266,7 @@ export default class Index { type, user_username: doc.username, user_name: doc.name, - user_email: _.map(doc.emails, (e) => { return e.address; }) + user_email: doc.emails && doc.emails.map((e) => { return e.address; }) }; default: throw new Error(`Cannot index type '${ type }'`); } @@ -428,14 +428,15 @@ export default class Index { } query(text, language, acl, type, start, rows, callback, params = {}) { - this._backend.query(_.extend(params, { + this._backend.query({ text, language, acl, type, start, - rows - }), callback); + rows, + ...params + }, callback); } suggest(text, language, acl, callback) { diff --git a/packages/rocketchat-search/client/provider/result.js b/packages/rocketchat-search/client/provider/result.js index 64b43fefb91d..5cb78c01408f 100644 --- a/packages/rocketchat-search/client/provider/result.js +++ b/packages/rocketchat-search/client/provider/result.js @@ -79,6 +79,6 @@ Template.DefaultSearchResultTemplate.helpers({ return Template.instance().hasMore.get(); }, message() { - return _.extend(this, { customClass: 'search', actionContext: 'search'}); + return { customClass: 'search', actionContext: 'search', ...this}; } }); diff --git a/packages/rocketchat-search/server/model/provider.js b/packages/rocketchat-search/server/model/provider.js index 86be3b3d889b..c6c0b72f6021 100644 --- a/packages/rocketchat-search/server/model/provider.js +++ b/packages/rocketchat-search/server/model/provider.js @@ -1,5 +1,4 @@ /*eslint no-unused-vars: [2, { "args": "none" }]*/ -import _ from 'underscore'; import SearchLogger from '../logger/logger'; /** @@ -49,7 +48,7 @@ class Settings { } list() { - return _.values(this.settings); + return Object.keys(this.settings).map(key => this.settings[key]); } map() { @@ -69,8 +68,8 @@ class Settings { * load currently stored values of all settings */ load() { - _.each(this.settings, (setting) => { - setting.load(); + Object.keys(this.settings).forEach((key) => { + this.settings[key].load(); }); } } @@ -159,8 +158,8 @@ export default class SearchProvider { } /*--- livecycle ---*/ - run(reason, callback) { - this._settings.load(); + run(reason, callback) {console.log(1111) + this._settings.load();console.log(2222) this.start(reason, callback); } diff --git a/packages/rocketchat-search/server/service/providerService.js b/packages/rocketchat-search/server/service/providerService.js index d6c9ae4fe08c..6369df48c5e2 100644 --- a/packages/rocketchat-search/server/service/providerService.js +++ b/packages/rocketchat-search/server/service/providerService.js @@ -93,28 +93,27 @@ class SearchProviderService { self.add('Search.Provider', 'defaultProvider', { type: 'select', - values: _.map(providers, (p) => { return {key:p.key, i18nLabel: p.i18nLabel}; }), + values: Object.keys(providers).map((key) => { return {key, i18nLabel: providers[key].i18nLabel}; }), public: true, i18nLabel: 'Search_Provider' }); - _.chain(providers) - .filter((provider) => provider.settings && provider.settings.length > 0) - .each(function(provider) { - self.section(provider.i18nLabel, function() { - provider.settings.forEach((setting) => { + Object.keys(providers) + .filter((key) => providers[key].settings && providers[key].settings.length > 0) + .forEach(function(key) { + self.section(providers[key].i18nLabel, function() { + providers[key].settings.forEach((setting) => { const _options = { - type: setting.type + type: setting.type, + ...setting.options }; - _.extend(_options, setting.options); - _options.enableQuery = _options.enableQuery || []; _options.enableQuery.push({ _id: 'Search.Provider', - value: provider.key + value: key }); this.add(setting.id, setting.defaultValue, _options); diff --git a/packages/rocketchat-search/server/service/validationService.js b/packages/rocketchat-search/server/service/validationService.js index 017bf308b775..08e54ebf8c21 100644 --- a/packages/rocketchat-search/server/service/validationService.js +++ b/packages/rocketchat-search/server/service/validationService.js @@ -1,5 +1,3 @@ -import _ from 'underscore'; - import SearchLogger from '../logger/logger'; class ValidationService { @@ -10,38 +8,38 @@ class ValidationService { const uid = Meteor.userId(); //get subscription for message if (result.message) { - result.message.docs = _.chain(result.message.docs) - .each((msg) => { - const subscription = Meteor.call('canAccessRoom', msg.rid, uid); - if (subscription) { - msg.r = {name: subscription.name, t: subscription.t}; - msg.username = subscription.username; - msg.valid = true; - SearchLogger.debug(`user ${ uid } can access ${ msg.rid } ( ${ subscription.t === 'd' ? subscription.username : subscription.name } )`); - } else { - SearchLogger.debug(`user ${ uid } can NOT access ${ msg.rid }`); - } - }) - .filter((msg) => { - SearchLogger.debug(JSON.stringify(msg, null, 2)); - return msg.valid; - }).value(); + result.message.docs.forEach((msg) => { + const subscription = Meteor.call('canAccessRoom', msg.rid, uid); + if (subscription) { + msg.r = {name: subscription.name, t: subscription.t}; + msg.username = subscription.username; + msg.valid = true; + SearchLogger.debug(`user ${ uid } can access ${ msg.rid } ( ${ subscription.t === 'd' ? subscription.username : subscription.name } )`); + } else { + SearchLogger.debug(`user ${ uid } can NOT access ${ msg.rid }`); + } + }); + + result.message.docs.filter((msg) => { + SearchLogger.debug(JSON.stringify(msg, null, 2)); + return msg.valid; + }); } if (result.room) { - result.room.docs = _.chain(result.room.docs) - .forEach((room) => { - const subscription = Meteor.call('canAccessRoom', room._id, uid); - if (subscription) { - room.valid = true; - SearchLogger.debug(`user ${ uid } can access ${ room._id } ( ${ subscription.t === 'd' ? subscription.username : subscription.name } )`); - } else { - SearchLogger.debug(`user ${ uid } can NOT access ${ room._id }`); - } - }) - .filter((room) => { - return room.valid; - }).value(); + result.room.docs.forEach((room) => { + const subscription = Meteor.call('canAccessRoom', room._id, uid); + if (subscription) { + room.valid = true; + SearchLogger.debug(`user ${ uid } can access ${ room._id } ( ${ subscription.t === 'd' ? subscription.username : subscription.name } )`); + } else { + SearchLogger.debug(`user ${ uid } can NOT access ${ room._id }`); + } + }); + + result.room.docs.filter((room) => { + return room.valid; + }); } return result;