Skip to content

Commit

Permalink
Add user to all default channels on username setup Fixes #405
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Aug 7, 2015
1 parent 3491380 commit a81af10
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions server/methods/setUsername.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,34 @@ Meteor.methods
throw new Meteor.Error 'username-invalid'

if not user.username?
# put user in general channel
ChatRoom.update 'GENERAL',
$addToSet:
usernames: username

if not ChatSubscription.findOne(rid: 'GENERAL', 'u._id': user._id)?
ChatSubscription.insert
rid: 'GENERAL'
name: 'general'
ts: new Date()
t: 'c'
f: true
open: true
alert: true
unread: 1
u:
_id: user._id
username: username

ChatMessage.insert
rid: 'GENERAL'
ts: new Date()
t: 'uj'
msg: ''
u:
_id: user._id
username: username
ChatRoom.find({default: true, t: {$in: ['c', 'p']}}).forEach (room) ->
# put user in default rooms
ChatRoom.update room._id,
$addToSet:
usernames: username

if not ChatSubscription.findOne(rid: room._id, 'u._id': user._id)?
ChatSubscription.insert
rid: room._id
name: room.name
ts: new Date()
t: room.t
f: false
open: true
alert: true
unread: 1
u:
_id: user._id
username: username

ChatMessage.insert
rid: room._id
ts: new Date()
t: 'uj'
msg: ''
u:
_id: user._id
username: username

Meteor.users.update({_id: user._id}, {$set: {username: username}})

Expand Down

0 comments on commit a81af10

Please sign in to comment.