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/packages/rocketchat-lib/server/functions/addUserToDefaultChannels.js

28 lines
942 B

RocketChat.addUserToDefaultChannels = function(user, silenced) {
RocketChat.callbacks.run('beforeJoinDefaultChannels', user);
const defaultRooms = RocketChat.models.Rooms.findByDefaultAndTypes(true, ['c', 'p'], {fields: {usernames: 0}}).fetch();
defaultRooms.forEach((room) => {
// put user in default rooms
const muted = room.ro && !RocketChat.authz.hasPermission(user._id, 'post-readonly');
RocketChat.models.Rooms.addUsernameById(room._id, user.username, muted);
if (!RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, user._id)) {
// Add a subscription to this user
RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, {
ts: new Date(),
open: true,
alert: true,
unread: 1,
userMentions: 1,
groupMentions: 0
});
// Insert user joined message
if (!silenced) {
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(room._id, user);
}
}
});
};