From f21e455cf3ed3d94985c66b94a18853d429b0f3f Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 4 Jun 2015 19:32:42 -0300 Subject: [PATCH] Sort usernames in room closes #151 --- server/methods/addUserToRoom.coffee | 6 ++++-- server/methods/sendMessage.coffee | 5 ++++- server/methods/setUsername.coffee | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/methods/addUserToRoom.coffee b/server/methods/addUserToRoom.coffee index 69f9862a5f8c..4c257bd524d2 100644 --- a/server/methods/addUserToRoom.coffee +++ b/server/methods/addUserToRoom.coffee @@ -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 diff --git a/server/methods/sendMessage.coffee b/server/methods/sendMessage.coffee index fc19ffb626d5..efb7f943f85a 100644 --- a/server/methods/sendMessage.coffee +++ b/server/methods/sendMessage.coffee @@ -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 diff --git a/server/methods/setUsername.coffee b/server/methods/setUsername.coffee index acfbb36112a4..ef0967580fe5 100644 --- a/server/methods/setUsername.coffee +++ b/server/methods/setUsername.coffee @@ -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