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

40 lines
892 B

Meteor.methods({
getUsersOfRoom(roomId, showAll) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getUsersOfRoom' });
}
const room = Meteor.call('canAccessRoom', roomId, Meteor.userId());
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getUsersOfRoom' });
}
const filter = (record) => {
if (!record._user) {
console.log('Subscription without user', record._id);
return false;
}
if (showAll === true) {
return true;
}
return record._user.status !== 'offline';
};
const map = (record) => {
return {
username: record._user.username,
name: record._user.name
};
};
const records = RocketChat.models.Subscriptions.findByRoomId(roomId).fetch();
return {
total: records.length,
records: records.filter(filter).map(map)
};
}
});