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

47 lines
1.2 KiB

RocketChat.addUserToRoom = function(rid, user, inviter, silenced) {
const now = new Date();
const room = RocketChat.models.Rooms.findOneById(rid);
// Check if user is already in room
const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
if (subscription) {
return;
}
if (room.t === 'c' || room.t === 'p') {
RocketChat.callbacks.run('beforeJoinRoom', user, room);
}
const muted = room.ro && !RocketChat.authz.hasPermission(user._id, 'post-readonly');
RocketChat.models.Rooms.addUsernameById(rid, user.username, muted);
RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, {
ts: now,
open: true,
alert: true,
unread: 1,
userMentions: 1,
groupMentions: 0
});
if (!silenced) {
if (inviter) {
RocketChat.models.Messages.createUserAddedWithRoomIdAndUser(rid, user, {
ts: now,
u: {
_id: inviter._id,
username: inviter.username
}
});
} else {
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(rid, user, { ts: now });
}
}
if (room.t === 'c' || room.t === 'p') {
Meteor.defer(function() {
RocketChat.callbacks.run('afterJoinRoom', user, room);
});
}
return true;
};