Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joinRoom returns if room is already added #856

Merged
merged 1 commit into from
Sep 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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