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/joinRoom.coffee

39 lines
1.1 KiB

Meteor.methods
joinRoom: (rid) ->
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'joinRoom' }
room = RocketChat.models.Rooms.findOneById rid
if not room?
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'joinRoom' }
if room.t isnt 'c' or RocketChat.authz.hasPermission(Meteor.userId(), 'view-c-room') isnt true
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'joinRoom' }
now = new Date()
# Check if user is already in room
subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId rid, Meteor.userId()
if subscription?
return
user = RocketChat.models.Users.findOneById Meteor.userId()
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 ->
RocketChat.callbacks.run 'afterJoinRoom', user, room
return true