Skip to content

Commit 6d949ef

Browse files
committed
Merge pull request #364 from RocketChat/sort-of-users-in-view
Sort of users in view
2 parents e5cecfc + 9f57039 commit 6d949ef

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

client/views/app/room.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ Template.room.helpers
192192
username: username
193193
status: onlineUsers[username]
194194

195+
users = _.sortBy users, 'username'
196+
195197
ret =
196198
_id: this._id
197199
total: room.usernames.length

packages/rocketchat-irc/irc.server.coffee

+5-6
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ class IrcClient
195195
$in: removeMembers
196196
ChatRoom.update room._id, update
197197
update =
198-
$push:
198+
$addToSet:
199199
usernames:
200200
$each: appendMembers
201-
$sort: 1
201+
202202
ChatRoom.update room._id, update
203203
@isJoiningRoom = false
204204
roomName = @pendingJoinRoomBuf.shift()
@@ -277,10 +277,9 @@ class IrcClient
277277
console.log '[irc] onAddMemberToRoom -> '.yellow, 'roomName:', roomName, 'member:', member
278278
@createUserWhenNotExist member
279279
update =
280-
$push:
281-
usernames:
282-
$each: [member]
283-
$sort: 1
280+
$addToSet:
281+
usernames: member
282+
284283
ChatRoom.update {name: roomName}, update
285284

286285
onRemoveMemberFromRoom: (member, roomName)->

server/methods/addUserToRoom.coffee

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ Meteor.methods
1616
now = new Date()
1717

1818
update =
19-
$push:
20-
usernames:
21-
$each: [data.username]
22-
$sort: 1
19+
$addToSet:
20+
usernames: data.username
2321

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

server/methods/joinRoom.coffee

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ Meteor.methods
1717
RocketChat.callbacks.run 'beforeJoinRoom', user, room
1818

1919
update =
20-
$push:
21-
usernames:
22-
$each: [user.username]
23-
$sort: 1
20+
$addToSet:
21+
usernames: user.username
2422

2523
ChatRoom.update rid, update
2624

server/methods/setUsername.coffee

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ Meteor.methods
1919
if not user.username?
2020
# put user in general channel
2121
ChatRoom.update 'GENERAL',
22-
$push:
23-
usernames:
24-
$each: [username]
25-
$sort: 1
22+
$addToSet:
23+
usernames: username
2624

2725
if not ChatSubscription.findOne(rid: 'GENERAL', 'u._id': user._id)?
2826
ChatSubscription.insert

server/startup/migrations/v10.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Meteor.startup ->
2+
Migrations.add
3+
version: 10
4+
up: ->
5+
###
6+
# Remove duplicated usernames from rooms
7+
###
8+
9+
count = 0
10+
ChatRoom.find({'usernames.0': {$exists: true}}, {fields: {usernames: 1}}).forEach (room) ->
11+
newUsernames = _.uniq room.usernames
12+
if newUsernames.length isnt room.usernames.length
13+
count++
14+
ChatRoom.update {_id: room._id}, {$set: {usernames: newUsernames}}
15+
16+
console.log "Removed duplicated usernames from #{count} rooms"

0 commit comments

Comments
 (0)