Skip to content

Commit

Permalink
joinRoom returns if room is already added. Also throws helpful error …
Browse files Browse the repository at this point in the history
…if room doesn't exist.
  • Loading branch information
geekgonecrazy committed Sep 22, 2015
1 parent f4c20fd commit aeb0878
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/methods/joinRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ Meteor.methods

room = RocketChat.models.Rooms.findOneById rid

console.log '[methods] joinRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

if not room?
throw new Meteor.Error 500, 'No channel with this id'

if room.t isnt 'c'
throw new Meteor.Error 403, '[methods] joinRoom -> Not allowed'

# verify if user is already in room
# if room.usernames.indexOf(user.username) is -1
console.log '[methods] joinRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

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
Expand Down

0 comments on commit aeb0878

Please sign in to comment.