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

40 lines
840 B

import { Meteor } from 'meteor/meteor';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { Spotlight } from '../lib/spotlight';
Meteor.methods({
spotlight(text, usernames = [], type = { users: true, rooms: true, mentions: false }, rid) {
const spotlight = new Spotlight();
const { mentions } = type;
if (text.startsWith('#')) {
type.users = false;
text = text.slice(1);
}
if (text.startsWith('@')) {
type.rooms = false;
text = text.slice(1);
}
const { userId } = this;
return {
users: type.users ? spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [],
rooms: type.rooms ? spotlight.searchRooms({ userId, text }) : [],
};
},
});
DDPRateLimiter.addRule(
{
type: 'method',
name: 'spotlight',
userId(/* userId*/) {
return true;
},
},
100,
100000,
);