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/methods/groupsList.js

42 lines
1.2 KiB

Meteor.methods({
groupsList(nameFilter, limit, sort) {
check(nameFilter, Match.Optional(String));
check(limit, Match.Optional(Number));
check(sort, Match.Optional(String));
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'groupsList' });
}
const options = {
fields: { name: 1 },
sort: { name: 1 }
};
//Verify the limit param is a number
if (_.isNumber(limit)) {
options.limit = limit;
}
//Verify there is a sort option and it's a string
if (_.trim(sort)) {
switch (sort) {
case 'name':
options.sort = { name: 1 };
break;
case 'msgs':
options.sort = { msgs: -1 };
break;
}
}
//Determine if they are searching or not, base it upon the name field
if (nameFilter) {
return { groups: RocketChat.models.Rooms.findByTypeAndNameContainingUsername('p', new RegExp(s.trim(s.escapeRegExp(nameFilter)), 'i'), Meteor.user().username, options).fetch() };
} else {
const roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('p', Meteor.userId()).fetch(), 'rid');
return { groups: RocketChat.models.Rooms.findByIds(roomIds, options).fetch() };
}
}
});