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

Sort of users in view #364

Merged
merged 3 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Template.room.helpers
username: username
status: onlineUsers[username]

users = _.sortBy users, 'username'

ret =
_id: this._id
total: room.usernames.length
Expand Down
11 changes: 5 additions & 6 deletions packages/rocketchat-irc/irc.server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ class IrcClient
$in: removeMembers
ChatRoom.update room._id, update
update =
$push:
$addToSet:
usernames:
$each: appendMembers
$sort: 1

ChatRoom.update room._id, update
@isJoiningRoom = false
roomName = @pendingJoinRoomBuf.shift()
Expand Down Expand Up @@ -277,10 +277,9 @@ class IrcClient
console.log '[irc] onAddMemberToRoom -> '.yellow, 'roomName:', roomName, 'member:', member
@createUserWhenNotExist member
update =
$push:
usernames:
$each: [member]
$sort: 1
$addToSet:
usernames: member

ChatRoom.update {name: roomName}, update

onRemoveMemberFromRoom: (member, roomName)->
Expand Down
6 changes: 2 additions & 4 deletions server/methods/addUserToRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ Meteor.methods
now = new Date()

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

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

Expand Down
6 changes: 2 additions & 4 deletions server/methods/joinRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ Meteor.methods
RocketChat.callbacks.run 'beforeJoinRoom', user, room

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

ChatRoom.update rid, update

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

if not ChatSubscription.findOne(rid: 'GENERAL', 'u._id': user._id)?
ChatSubscription.insert
Expand Down
16 changes: 16 additions & 0 deletions server/startup/migrations/v10.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Meteor.startup ->
Migrations.add
version: 10
up: ->
###
# Remove duplicated usernames from rooms
###

count = 0
ChatRoom.find({'usernames.0': {$exists: true}}, {fields: {usernames: 1}}).forEach (room) ->
newUsernames = _.uniq room.usernames
if newUsernames.length isnt room.usernames.length
count++
ChatRoom.update {_id: room._id}, {$set: {usernames: newUsernames}}

console.log "Removed duplicated usernames from #{count} rooms"