The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/publications/spotlight.js

53 lines
1.1 KiB

Meteor.methods({
spotlight(text, usernames, type = {users: true, rooms: true}) {
const result = {
users: [],
rooms: []
};
if (this.userId == null) {
return result;
}
const regex = new RegExp(s.trim(s.escapeRegExp(text)), 'i');
if (type.users === true && RocketChat.authz.hasPermission(this.userId, 'view-d-room')) {
result.users = RocketChat.models.Users.findByActiveUsersUsernameExcept(text, usernames, {
limit: 5,
fields: {
username: 1,
status: 1
},
sort: {
username: 1
}
}).fetch();
}
if (type.rooms === true && RocketChat.authz.hasPermission(this.userId, 'view-c-room')) {
const username = RocketChat.models.Users.findOneById(this.userId, {
username: 1
}).username;
result.rooms = RocketChat.models.Rooms.findByNameAndTypeNotContainingUsername(regex, 'c', username, {
limit: 5,
fields: {
t: 1,
name: 1
},
sort: {
name: 1
}
}).fetch();
}
return result;
}
});
DDPRateLimiter.addRule({
type: 'method',
name: 'spotlight',
userId(/*userId*/) {
return true;
}
}, 100, 100000);