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

51 lines
1.4 KiB

Meteor.methods({
addAllUserToRoom: function(rid) {
9 years ago
check (rid, String);
if (RocketChat.authz.hasRole(this.userId, 'admin') === true) {
const userCount = RocketChat.models.Users.find().count();
if (userCount > RocketChat.settings.get('API_User_Limit')) {
throw new Meteor.Error('error-user-limit-exceeded', 'User Limit Exceeded', {
method: 'addAllToRoom'
});
}
const room = RocketChat.models.Rooms.findOneById(rid);
if (room == null) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'addAllToRoom'
});
}
const users = RocketChat.models.Users.find().fetch();
const now = new Date();
users.forEach(function(user) {
var subscription;
subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
if (subscription != null) {
return;
}
RocketChat.callbacks.run('beforeJoinRoom', user, room);
RocketChat.models.Rooms.addUsernameById(rid, user.username);
RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, {
ts: now,
open: true,
alert: true,
unread: 1
});
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(rid, user, {
ts: now
});
Meteor.defer(function() {});
return RocketChat.callbacks.run('afterJoinRoom', user, room);
});
return true;
} else {
throw (new Meteor.Error(403, 'Access to Method Forbidden', {
method: 'addAllToRoom'
}));
}
}
});