Add eslit rule `one-var`

pull/6458/head
Rodrigo Nascimento 9 years ago
parent 47d5a17b3c
commit 4e889bc854
  1. 1
      .eslintrc
  2. 5
      client/startup/userSetUtcOffset.js
  3. 3
      lib/fileUpload.js
  4. 4
      packages/rocketchat-file-upload/server/config/configFileUploadAmazonS3.js
  5. 4
      packages/rocketchat-file-upload/server/config/configFileUploadGridFS.js
  6. 6
      packages/rocketchat-file-upload/server/lib/requests.js
  7. 5
      packages/rocketchat-file-upload/server/methods/getS3FileUrl.js
  8. 8
      packages/rocketchat-integrations/client/views/integrationsOutgoing.js
  9. 7
      packages/rocketchat-lib/lib/fileUploadRestrictions.js
  10. 3
      packages/rocketchat-lib/server/functions/saveUser.js
  11. 3
      packages/rocketchat-lib/server/functions/setUserAvatar.js
  12. 4
      packages/rocketchat-lib/server/lib/PushNotification.js
  13. 10
      packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
  14. 5
      packages/rocketchat-lib/server/lib/sendEmailOnMessage.js
  15. 60
      packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
  16. 12
      packages/rocketchat-lib/server/methods/updateMessage.js
  17. 10
      packages/rocketchat-livechat/app/client/views/messages.js
  18. 5
      packages/rocketchat-livechat/app/client/views/register.js
  19. 8
      packages/rocketchat-message-snippet/server/requests.js
  20. 8
      packages/rocketchat-slackbridge/slashcommand/slackbridge_import.server.js
  21. 9
      packages/rocketchat-slashcommands-archiveroom/server.js
  22. 10
      packages/rocketchat-slashcommands-create/server.js
  23. 4
      packages/rocketchat-slashcommands-inviteall/server.js
  24. 9
      packages/rocketchat-slashcommands-open/client.js
  25. 8
      packages/rocketchat-slashcommands-unarchiveroom/server.js
  26. 40
      packages/rocketchat-ui-flextab/client/tabs/userInfo.js
  27. 3
      server/lib/cordova.js
  28. 11
      server/methods/addAllUserToRoom.js
  29. 44
      server/methods/messageSearch.js

@ -48,6 +48,7 @@
"vars": "all",
"args": "after-used"
}],
"one-var": [2, "never"],
"no-lonely-if": 2,
"no-trailing-spaces": 2,
"complexity": [1, 31],

@ -2,10 +2,9 @@ import moment from 'moment';
Meteor.startup(function() {
Tracker.autorun(function() {
var user, utcOffset;
user = Meteor.user();
const user = Meteor.user();
if (user && user.statusConnection === 'online') {
utcOffset = moment().utcOffset() / 60;
const utcOffset = moment().utcOffset() / 60;
if (user.utcOffset !== utcOffset) {
Meteor.call('userSetUtcOffset', utcOffset);
}

@ -45,7 +45,8 @@ if (UploadFS) {
onRead(fileId, file, req, res) {
if (RocketChat.settings.get('FileUpload_ProtectFiles')) {
let uid, token;
let uid;
let token;
if (req && req.headers && req.headers.cookie) {
const rawCookies = req.headers.cookie;

@ -1,7 +1,9 @@
/* globals Slingshot, FileUpload, AWS, SystemLogger */
const crypto = Npm.require('crypto');
let S3accessKey, S3secretKey, S3expiryTimeSpan;
let S3accessKey;
let S3secretKey;
let S3expiryTimeSpan;
const generateURL = function(file) {
if (!file || !file.s3) {

@ -25,7 +25,9 @@ ExtractRange.prototype._transform = function(chunk, enc, cb) {
} else if (this.bytes_read + chunk.length < this.start) {
// this chunk is still before the start byte
} else {
let start, stop;
let start;
let stop;
if (this.start <= this.bytes_read) {
start = 0;
} else {

@ -15,10 +15,12 @@ WebApp.connectHandlers.use('/file-upload/', function(req, res, next) {
if (file) {
if (!Meteor.settings.public.sandstorm && protectedFiles) {
let rawCookies, ref, token, uid;
let rawCookies;
let token;
let uid;
const cookie = new Cookies();
if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) != null ? ref.cookie : void 0 : void 0) != null) {
if (req.headers && req.headers.cookie != null) {
rawCookies = req.headers.cookie;
}

@ -1,5 +1,8 @@
const crypto = Npm.require('crypto');
let protectedFiles, S3accessKey, S3secretKey, S3expiryTimeSpan;
let protectedFiles;
let S3accessKey;
let S3secretKey;
let S3expiryTimeSpan;
RocketChat.settings.get('FileUpload_ProtectFiles', function(key, value) {
protectedFiles = value;

@ -285,7 +285,8 @@ Template.integrationsOutgoing.events({
return toastr.error(TAPi18n.__('You_should_inform_one_url_at_least'));
}
let triggerWords, triggerWordAnywhere;
let triggerWords;
let triggerWordAnywhere;
if (RocketChat.integrations.outgoingEvents[event].use.triggerWords) {
triggerWords = $('[name=triggerWords]').val().trim();
triggerWords = triggerWords.split(',').filter((word) => word.trim() !== '');
@ -311,10 +312,11 @@ Template.integrationsOutgoing.events({
}
}
let retryCount, retryDelay;
let retryCount;
let retryDelay;
if (retryFailedCalls === '1') {
retryCount = parseInt($('[name=retryCount]').val().trim());
retryDelay: $('[name=retryDelay]').val().trim();
retryDelay = $('[name=retryDelay]').val().trim();
}
const integration = {

@ -10,13 +10,12 @@ RocketChat.fileUploadMediaWhiteList = function() {
};
RocketChat.fileUploadIsValidContentType = function(type) {
var list, wildCardGlob, wildcards;
list = RocketChat.fileUploadMediaWhiteList();
const list = RocketChat.fileUploadMediaWhiteList();
if (!list || _.contains(list, type)) {
return true;
} else {
wildCardGlob = '/*';
wildcards = _.filter(list, function(item) {
const wildCardGlob = '/*';
const wildcards = _.filter(list, function(item) {
return item.indexOf(wildCardGlob) > 0;
});
if (_.contains(wildcards, type.replace(/(\/.*)$/, wildCardGlob))) {

@ -87,7 +87,8 @@ RocketChat.saveUser = function(userId, userData) {
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
let subject, html;
let subject;
let html;
if (RocketChat.settings.get('Accounts_UserAddedEmail_Customized')) {
subject = RocketChat.settings.get('Accounts_UserAddedEmailSubject');

@ -1,5 +1,6 @@
RocketChat.setUserAvatar = function(user, dataURI, contentType, service) {
let encoding, image;
let encoding;
let image;
if (service === 'initials') {
return RocketChat.models.Users.setAvatarOrigin(user._id, service);

@ -6,8 +6,8 @@ class PushNotification {
}
hash(str) {
let hash = 0,
i = str.length;
let hash = 0;
let i = str.length;
while (i) {
hash = ((hash << 5) - hash) + str.charCodeAt(--i);

@ -43,12 +43,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
// Update the other subscriptions
RocketChat.models.Subscriptions.incUnreadOfDirectForRoomIdExcludingUserId(message.rid, message.u._id, 1);
} else {
var mentionIds, toAll, highlightsIds, highlights;
mentionIds = [];
highlightsIds = [];
toAll = false;
highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
let toAll = false;
const mentionIds = [];
const highlightsIds = [];
const highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
if (message.mentions != null) {
message.mentions.forEach(function(mention) {

@ -10,8 +10,9 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}
var emailSubject, usersToSendEmail = {};
var directMessage = room.t === 'd';
let emailSubject;
const usersToSendEmail = {};
const directMessage = room.t === 'd';
if (directMessage) {
usersToSendEmail[message.rid.replace(message.u._id, '')] = 1;

@ -16,16 +16,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
/*
Increment unread couter if direct messages
*/
var indexOf = [].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item) {
return i;
}
}
return -1;
};
var settings, desktopMentionIds, i, j, len, len1, highlights, mentionIds, highlightsIds, usersWithHighlights, mobileMentionIds, ref, ref1, toAll, toHere, userIdsToNotify, userIdsToPushNotify, userOfMention, userOfMentionId, usersOfDesktopMentions, usersOfMentionId, usersOfMentionItem, usersOfMobileMentions;
const settings = {};
/**
* Checks if a given user can be notified
@ -67,8 +58,6 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return has;
}
settings = {};
settings.alwaysNotifyDesktopUsers = [];
settings.dontNotifyDesktopUsers = [];
settings.alwaysNotifyMobileUsers = [];
@ -90,11 +79,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration;
});
userIdsToNotify = [];
userIdsToPushNotify = [];
usersWithHighlights = [];
let userIdsToNotify = [];
let userIdsToPushNotify = [];
const usersWithHighlights = [];
highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
const highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
highlights.forEach(function(user) {
if (messageContainsHighlight(message, user.settings.preferences.highlights)) {
@ -120,9 +109,9 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
push_room = '';
}
if ((room.t == null) || room.t === 'd') {
userOfMentionId = message.rid.replace(message.u._id, '');
userOfMention = RocketChat.models.Users.findOne({
if (room.t == null || room.t === 'd') {
const userOfMentionId = message.rid.replace(message.u._id, '');
const userOfMention = RocketChat.models.Users.findOne({
_id: userOfMentionId
}, {
fields: {
@ -174,19 +163,19 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
} else {
mentionIds = [];
if ((ref = message.mentions) != null) {
ref.forEach(function(mention) {
const mentionIds = [];
if (message.mentions != null) {
message.mentions.forEach(function(mention) {
return mentionIds.push(mention._id);
});
}
toAll = mentionIds.indexOf('all') > -1;
toHere = mentionIds.indexOf('here') > -1;
const toAll = mentionIds.indexOf('all') > -1;
const toHere = mentionIds.indexOf('here') > -1;
if (mentionIds.length > 0 || settings.alwaysNotifyDesktopUsers.length > 0) {
desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers);
let desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers);
desktopMentionIds = _.difference(desktopMentionIds, settings.dontNotifyDesktopUsers);
usersOfDesktopMentions = RocketChat.models.Users.find({
let usersOfDesktopMentions = RocketChat.models.Users.find({
_id: {
$in: desktopMentionIds
}
@ -205,8 +194,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
});
}
};
for (i = 0, len = usersOfDesktopMentions.length; i < len; i++) {
usersOfMentionItem = usersOfDesktopMentions[i];
for (const usersOfMentionItem of usersOfDesktopMentions) {
if (room.usernames.indexOf(usersOfMentionItem.username) === -1) {
callJoin(usersOfMentionItem);
}
@ -223,10 +211,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
if (mentionIds.length > 0 || settings.alwaysNotifyMobileUsers.length > 0) {
mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers);
let mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers);
mobileMentionIds = _.difference(mobileMentionIds, settings.dontNotifyMobileUsers);
usersOfMobileMentions = RocketChat.models.Users.find({
let usersOfMobileMentions = RocketChat.models.Users.find({
_id: {
$in: mobileMentionIds
}
@ -249,7 +237,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}), '_id');
}
if ((toAll || toHere) && ((ref1 = room.usernames) != null ? ref1.length : void 0) > 0) {
if ((toAll || toHere) && room.usernames && room.usernames.length > 0) {
RocketChat.models.Users.find({
username: {
$in: room.usernames
@ -265,18 +253,17 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
statusConnection: 1
}
}).forEach(function(user) {
var ref2, ref3, ref4;
if (((ref2 = user.status) === 'online' || ref2 === 'away' || ref2 === 'busy') && (ref3 = user._id, indexOf.call(settings.dontNotifyDesktopUsers, ref3) < 0)) {
if (['online', 'away', 'busy'].includes(user.status) && (settings.dontNotifyDesktopUsers || []).includes(user._id) === false) {
userIdsToNotify.push(user._id);
}
if (toAll && user.statusConnection !== 'online' && (ref4 = user._id, indexOf.call(settings.dontNotifyMobileUsers, ref4) < 0)) {
if (toAll && user.statusConnection !== 'online' && (settings.dontNotifyMobileUsers || []).includes(user._id) === false) {
return userIdsToPushNotify.push(user._id);
}
});
}
if (usersWithHighlights.length > 0) {
highlightsIds = _.pluck(usersWithHighlights, '_id');
const highlightsIds = _.pluck(usersWithHighlights, '_id');
userIdsToNotify = userIdsToNotify.concat(highlightsIds);
userIdsToPushNotify = userIdsToPushNotify.concat(highlightsIds);
}
@ -285,8 +272,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
userIdsToPushNotify = _.without(_.compact(_.unique(userIdsToPushNotify)), message.u._id);
if (userIdsToNotify.length > 0) {
for (j = 0, len1 = userIdsToNotify.length; j < len1; j++) {
usersOfMentionId = userIdsToNotify[j];
for (const usersOfMentionId of userIdsToNotify) {
let title = '@' + user.username;
if (room.name) {
title += ' @ #' + room.name;

@ -25,9 +25,15 @@ Meteor.methods({
const blockEditInMinutes = RocketChat.settings.get('Message_AllowEditing_BlockEditInMinutes');
if (Match.test(blockEditInMinutes, Number) && blockEditInMinutes !== 0) {
let currentTsDiff, msgTs;
if (Match.test(originalMessage.ts, Number)) { msgTs = moment(originalMessage.ts); }
if (msgTs) { currentTsDiff = moment().diff(msgTs, 'minutes'); }
let currentTsDiff;
let msgTs;
if (Match.test(originalMessage.ts, Number)) {
msgTs = moment(originalMessage.ts);
}
if (msgTs) {
currentTsDiff = moment().diff(msgTs, 'minutes');
}
if (currentTsDiff > blockEditInMinutes) {
throw new Meteor.Error('error-message-editing-blocked', 'Message editing is blocked', { method: 'updateMessage' });
}

@ -168,12 +168,12 @@ Template.messages.onRendered(function() {
});
Template.messages.onRendered(function() {
var messages, newMessage, onscroll, template;
messages = this.find('.messages');
newMessage = this.find('.new-message');
template = this;
const messages = this.find('.messages');
const newMessage = this.find('.new-message');
const template = this;
if (messages) {
onscroll = _.throttle(function() {
const onscroll = _.throttle(function() {
template.atBottom = messages.scrollTop >= messages.scrollHeight - messages.clientHeight;
}, 200);
Meteor.setInterval(function() {

@ -23,7 +23,6 @@ Template.register.helpers({
Template.register.events({
'submit #livechat-registration'(e, instance) {
var $email, $name;
e.preventDefault();
const start = () => {
@ -33,8 +32,8 @@ Template.register.events({
}
};
$name = instance.$('input[name=name]');
$email = instance.$('input[name=email]');
const $name = instance.$('input[name=name]');
const $email = instance.$('input[name=email]');
if (!($name.val().trim() && $email.val().trim())) {
return instance.showError(TAPi18n.__('Please_fill_name_and_email'));
} else {

@ -1,9 +1,11 @@
/* global Cookies */
WebApp.connectHandlers.use('/snippet/download', function(req, res) {
var cookie, rawCookies, ref, token, uid;
cookie = new Cookies();
let rawCookies;
let token;
let uid;
const cookie = new Cookies();
if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) !== null ? ref.cookie : void 0 : void 0) !== null) {
if (req.headers && req.headers.cookie !== null) {
rawCookies = req.headers.cookie;
}

@ -1,12 +1,12 @@
/* globals msgStream */
function SlackBridgeImport(command, params, item) {
var channel, room, user;
if (command !== 'slackbridge-import' || !Match.test(params, String)) {
return;
}
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
user = Meteor.users.findOne(Meteor.userId());
const room = RocketChat.models.Rooms.findOneById(item.rid);
const channel = room.name;
const user = Meteor.users.findOne(Meteor.userId());
msgStream.emit(item.rid, {
_id: Random.id(),

@ -1,9 +1,11 @@
function Archive(command, params, item) {
var channel, room, user;
if (command !== 'archive' || !Match.test(params, String)) {
return;
}
channel = params.trim();
let channel = params.trim();
let room;
if (channel === '') {
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
@ -11,7 +13,8 @@ function Archive(command, params, item) {
channel = channel.replace('#', '');
room = RocketChat.models.Rooms.findOneByName(channel);
}
user = Meteor.users.findOne(Meteor.userId());
const user = Meteor.users.findOne(Meteor.userId());
if (room.archived) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {

@ -11,19 +11,19 @@ function Create(command, params, item) {
}
return result;
}
var channel, room, user;
var regexp = /#?([\d-_\w]+)/g;
const regexp = /#?([\d-_\w]+)/g;
if (command !== 'create' || !Match.test(params, String)) {
return;
}
channel = regexp.exec(params.trim());
let channel = regexp.exec(params.trim());
channel = channel ? channel[1] : '';
if (channel === '') {
return;
}
user = Meteor.users.findOne(Meteor.userId());
room = RocketChat.models.Rooms.findOneByName(channel);
const user = Meteor.users.findOne(Meteor.userId());
const room = RocketChat.models.Rooms.findOneByName(channel);
if (room != null) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),

@ -11,8 +11,8 @@ function inviteAll(type) {
return;
}
const regexp = /#?([\d-_\w]+)/g,
[, channel] = regexp.exec(params.trim());
const regexp = /#?([\d-_\w]+)/g;
const [, channel] = regexp.exec(params.trim());
if (!channel) {
return;

@ -3,14 +3,13 @@ function Open(command, params /*, item*/) {
'#': ['c', 'p'],
'@': ['d']
};
var room, subscription, type;
if (command !== 'open' || !Match.test(params, String)) {
return;
}
room = params.trim();
type = dict[room[0]];
let room = params.trim();
const type = dict[room[0]];
room = room.replace(/#|@/, '');
var query = {
@ -23,7 +22,7 @@ function Open(command, params /*, item*/) {
};
}
subscription = ChatSubscription.findOne(query);
const subscription = ChatSubscription.findOne(query);
if (subscription) {
RocketChat.roomTypes.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams);
@ -36,7 +35,7 @@ function Open(command, params /*, item*/) {
if (err) {
return;
}
subscription = RocketChat.models.Subscriptions.findOne(query);
const subscription = RocketChat.models.Subscriptions.findOne(query);
RocketChat.roomTypes.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams);
});

@ -1,9 +1,11 @@
function Unarchive(command, params, item) {
var channel, room, user;
if (command !== 'unarchive' || !Match.test(params, String)) {
return;
}
channel = params.trim();
let channel = params.trim();
let room;
if (channel === '') {
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
@ -11,7 +13,7 @@ function Unarchive(command, params, item) {
channel = channel.replace('#', '');
room = RocketChat.models.Rooms.findOneByName(channel);
}
user = Meteor.users.findOne(Meteor.userId());
const user = Meteor.users.findOne(Meteor.userId());
if (!room.archived) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {

@ -196,8 +196,7 @@ Template.userInfo.events({
}
});
}
}
);
});
},
'click .back'(e, instance) {
@ -234,10 +233,8 @@ Template.userInfo.events({
});
return instance.clear();
}
);
}
);
});
});
} else {
return toastr.error(TAPi18n.__('error-not-allowed'));
}
@ -272,8 +269,7 @@ Template.userInfo.events({
showConfirmButton: false
});
});
}
);
});
}
},
@ -506,7 +502,6 @@ Template.userInfo.events({
});
Template.userInfo.onCreated(function() {
let data, user, username;
this.now = new ReactiveVar(moment());
this.user = new ReactiveVar;
this.editingUser = new ReactiveVar;
@ -520,7 +515,7 @@ Template.userInfo.onCreated(function() {
, 30000);
this.autorun(() => {
username = this.loadedUsername.get();
const username = this.loadedUsername.get();
if (username == null) {
this.loadingUserInfo.set(false);
@ -531,38 +526,33 @@ Template.userInfo.onCreated(function() {
return this.subscribe('fullUserData', username, 1, () => {
return this.loadingUserInfo.set(false);
}
);
}
);
});
});
this.autorun(() => {
data = Template.currentData();
const data = Template.currentData();
if (data.clear != null) {
return this.clear = data.clear;
}
}
);
});
this.autorun(() => {
data = Template.currentData();
user = this.user.get();
const data = Template.currentData();
const user = this.user.get();
return this.loadedUsername.set((user != null ? user.username : undefined) || (data != null ? data.username : undefined));
}
);
});
return this.autorun(() => {
let filter;
data = Template.currentData();
const data = Template.currentData();
if (data && data.username != null) {
filter = { username: data.username };
} else if (data && data._id != null) {
filter = { _id: data._id };
}
user = Meteor.users.findOne(filter);
const user = Meteor.users.findOne(filter);
return this.user.set(user);
}
);
});
});

@ -122,7 +122,8 @@ function configurePush() {
}
});
let apn, gcm;
let apn;
let gcm;
if (RocketChat.settings.get('Push_enable_gateway') === false) {
gcm = {

@ -4,21 +4,22 @@ Meteor.methods({
check (rid, String);
if (RocketChat.authz.hasRole(this.userId, 'admin') === true) {
var now, room, users;
var userCount = RocketChat.models.Users.find().count();
const userCount = RocketChat.models.Users.find().count();
if (userCount > RocketChat.settings.get('API_User_Limit')) {
throw new Meteor.Error('error-user-limit-exceeded', 'User Limit Exceeded', {
method: 'addAllToRoom'
});
}
room = RocketChat.models.Rooms.findOneById(rid);
const room = RocketChat.models.Rooms.findOneById(rid);
if (room == null) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'addAllToRoom'
});
}
users = RocketChat.models.Users.find().fetch();
now = new Date();
const users = RocketChat.models.Users.find().fetch();
const now = new Date();
users.forEach(function(user) {
var subscription;
subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);

@ -1,17 +1,30 @@
Meteor.methods({
messageSearch: function(text, rid, limit) {
var from, mention, options, query, r, result, currentUserName, currentUserId, currentUserTimezoneOffset;
const result = {
messages: [],
users: [],
channels: []
};
const query = {};
const options = {
sort: {
ts: -1
},
limit: limit || 20
};
check(text, String);
check(rid, String);
check(limit, Match.Optional(Number));
currentUserId = Meteor.userId();
const currentUserId = Meteor.userId();
if (!currentUserId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'messageSearch'
});
}
currentUserName = Meteor.user().username;
currentUserTimezoneOffset = Meteor.user().utcOffset;
const currentUserName = Meteor.user().username;
const currentUserTimezoneOffset = Meteor.user().utcOffset;
// I would place these methods at the bottom of the file for clarity but travis doesn't appreciate that.
// (no-use-before-define)
@ -67,10 +80,9 @@ Meteor.methods({
function filterOnDate(_, day, month, year) {
month--;
var date, dayAfter;
date = new Date(year, month, day);
const date = new Date(year, month, day);
date.setUTCHours(date.getUTCHours() + date.getTimezoneOffset()/60 + currentUserTimezoneOffset);
dayAfter = new Date(date);
const dayAfter = new Date(date);
dayAfter.setDate(dayAfter.getDate() + 1);
delete query.ts;
query.ts = {
@ -92,21 +104,9 @@ Meteor.methods({
/*
text = 'from:rodrigo mention:gabriel chat'
*/
result = {
messages: [],
users: [],
channels: []
};
query = {};
options = {
sort: {
ts: -1
},
limit: limit || 20
};
// Query for senders
from = [];
const from = [];
text = text.replace(/from:([a-z0-9.-_]+)/ig, function(match, username) {
if (username === 'me' && !from.includes(currentUserName)) {
username = currentUserName;
@ -121,7 +121,7 @@ Meteor.methods({
};
}
// Query for senders
mention = [];
const mention = [];
text = text.replace(/mention:([a-z0-9.-_]+)/ig, function(match, username) {
mention.push(username);
return '';
@ -154,7 +154,7 @@ Meteor.methods({
text = text.trim().replace(/\s\s/g, ' ');
if (text !== '') {
if (/^\/.+\/[imxs]*$/.test(text)) {
r = text.split('/');
const r = text.split('/');
query.msg = {
$regex: r[1],
$options: r[2]

Loading…
Cancel
Save