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/getUsersOfRoom.js

30 lines
1.1 KiB

Meteor.methods({
getUsersOfRoom(rid, showAll) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getUsersOfRoom' });
}
const room = Meteor.call('canAccessRoom', rid, userId);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getUsersOfRoom' });
}
if (room.broadcast && !RocketChat.authz.hasPermission(userId, 'view-broadcast-member-list', rid)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getUsersOfRoom' });
}
const subscriptions = RocketChat.models.Subscriptions.findByRoomIdWhenUsernameExists(rid, { fields: { 'u._id': 1 } }).fetch();
const userIds = subscriptions.map((s) => s.u._id); // TODO: CACHE: expensive
const options = { fields: { username: 1, name: 1 } };
const users = showAll === true
? RocketChat.models.Users.findUsersWithUsernameByIds(userIds, options).fetch()
: RocketChat.models.Users.findUsersWithUsernameByIdsNotOffline(userIds, options).fetch();
return {
total: userIds.length,
records: users,
};
},
});