Skip to content

Commit

Permalink
#8381 removes underscore functions where it is possible (fixes Rocket…
Browse files Browse the repository at this point in the history
  • Loading branch information
tkurz committed Apr 15, 2018
1 parent 44b707d commit 8d8fe8b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 33 additions & 32 deletions packages/chatpal-search/server/provider/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'underscore';
import ChatpalLogger from '../utils/logger';
import { Random } from 'meteor/random';

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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));

Expand Down Expand Up @@ -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); }
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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 }'`);
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-search/client/provider/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
});
11 changes: 5 additions & 6 deletions packages/rocketchat-search/server/model/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*eslint no-unused-vars: [2, { "args": "none" }]*/
import _ from 'underscore';
import SearchLogger from '../logger/logger';

/**
Expand Down Expand Up @@ -49,7 +48,7 @@ class Settings {
}

list() {
return _.values(this.settings);
return Object.keys(this.settings).map(key => this.settings[key]);
}

map() {
Expand All @@ -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();
});
}
}
Expand Down Expand Up @@ -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);
}

Expand Down
19 changes: 9 additions & 10 deletions packages/rocketchat-search/server/service/providerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 29 additions & 31 deletions packages/rocketchat-search/server/service/validationService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'underscore';

import SearchLogger from '../logger/logger';

class ValidationService {
Expand All @@ -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;
Expand Down

0 comments on commit 8d8fe8b

Please sign in to comment.