Skip to content

Commit

Permalink
Sort usernames in room closes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Jun 4, 2015
1 parent 8645763 commit f21e455
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions server/methods/addUserToRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Meteor.methods
return

update =
$addToSet:
usernames: data.username
$push:
usernames:
$each: [data.username]
$sort: 1

newUser = Meteor.users.findOne username: data.username

Expand Down
5 changes: 4 additions & 1 deletion server/methods/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Meteor.methods
roomUpdate = { $set: { lm: now }, $inc: { msgs: 1 } }

if Meteor.userId() and not Meteor.user().username in roomData.usernames
roomUpdate.$push = { usernames: Meteor.user().username }
roomUpdate.$push =
usernames:
$each: [ Meteor.user().username ]
$sort: 1

ChatRoom.update rid, roomUpdate

Expand Down
6 changes: 4 additions & 2 deletions server/methods/setUsername.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Meteor.methods
if not user.username?
# put user in general channel
ChatRoom.update '57om6EQCcFami9wuT',
$addToSet:
usernames: username
$push:
usernames:
$each: [username]
$sort: 1

if not ChatSubscription.findOne(rid: '57om6EQCcFami9wuT', 'u._id': user._id)?
ChatSubscription.insert
Expand Down

0 comments on commit f21e455

Please sign in to comment.