Skip to content

Commit

Permalink
Merge pull request #856 from RocketChat/joinroom-mod
Browse files Browse the repository at this point in the history
joinRoom returns if room is already added
  • Loading branch information
geekgonecrazy committed Sep 23, 2015
2 parents b14954a + aeb0878 commit 6ce58de
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 6ce58de

Please sign in to comment.