From 45c2884d8e8d822e64711005cbc6de8a3d5c0cff Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 3 Jun 2015 20:07:09 -0300 Subject: [PATCH] Fix users status --- client/lib/UserManager.coffee | 12 +++++----- client/startup/startup.coffee | 8 +++---- client/views/app/chatMessageDashboard.coffee | 4 ++-- client/views/app/chatWindowDashboard.coffee | 24 ++++++++++---------- client/views/app/sideNav/chatRoomItem.coffee | 9 ++++---- client/views/app/sideNav/userStatus.coffee | 9 ++++---- client/views/app/userImageProfile.coffee | 5 +--- client/views/app/userImageProfile.html | 6 ++--- server/publications.coffee | 11 +++++---- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/client/lib/UserManager.coffee b/client/lib/UserManager.coffee index be3dcfd4a83..784a889f258 100644 --- a/client/lib/UserManager.coffee +++ b/client/lib/UserManager.coffee @@ -3,12 +3,12 @@ dep = new Tracker.Dependency - addUser = (userIds) -> - # console.log 'addUser', userIds if window.rocketUserDebug - userIds = [].concat userIds - for userId in userIds - unless users[userId] - users[userId] = 1 + addUser = (usernames) -> + # console.log 'addUser', usernames if window.rocketUserDebug + usernames = [].concat usernames + for username in usernames + unless users[username] + users[username] = 1 dep.changed() subscribeFn = -> diff --git a/client/startup/startup.coffee b/client/startup/startup.coffee index 1ec645e9af3..902789d1265 100644 --- a/client/startup/startup.coffee +++ b/client/startup/startup.coffee @@ -26,17 +26,17 @@ Meteor.startup -> TAPi18n.setLanguage(userLanguage) moment.locale(userLanguage) - Meteor.users.find({}, { fields: { name: 1, pictures: 1, status: 1, emails: 1, phone: 1, services: 1 } }).observe + Meteor.users.find({}, { fields: { name: 1, username: 1, pictures: 1, status: 1, emails: 1, phone: 1, services: 1 } }).observe added: (user) -> - Session.set('user_' + user._id + '_status', user.status) + Session.set('user_' + user.username + '_status', user.status) UserAndRoom.insert({ type: 'u', uid: user._id, name: user.name}) changed: (user) -> - Session.set('user_' + user._id + '_status', user.status) + Session.set('user_' + user.username + '_status', user.status) UserAndRoom.update({ uid: user._id }, { $set: { name: user.name } }) removed: (user) -> - Session.set('user_' + user._id + '_status', null) + Session.set('user_' + user.username + '_status', null) UserAndRoom.remove({ uid: user._id }) diff --git a/client/views/app/chatMessageDashboard.coffee b/client/views/app/chatMessageDashboard.coffee index 59c4b925926..160111956f1 100644 --- a/client/views/app/chatMessageDashboard.coffee +++ b/client/views/app/chatMessageDashboard.coffee @@ -29,8 +29,8 @@ Template.chatMessageDashboard.helpers message: -> if this.by UserManager.addUser(this.by) - else if this.uid - UserManager.addUser(this.uid) + else if this.u?.username + UserManager.addUser this.u.username switch this.t when 'p' then "#{this.msg}" when 'r' then t('chatMessageDashboard.Room_name_changed', { room_name: this.msg, user_by: Session.get('user_' + this.by + '_name') }) + '.' diff --git a/client/views/app/chatWindowDashboard.coffee b/client/views/app/chatWindowDashboard.coffee index e648650010c..609352a5be7 100644 --- a/client/views/app/chatWindowDashboard.coffee +++ b/client/views/app/chatWindowDashboard.coffee @@ -243,23 +243,23 @@ Template.chatWindowDashboard.helpers _id: this._id total: room?.usernames.length totalOnline: 0 - users: [] + users: room.usernames - if room?.usernames - # UserManager.addUser room.uids + # if room?.usernames + # # UserManager.addUser room.uids - filter = - username: - $in: room.usernames + # filter = + # username: + # $in: room.usernames - # unless Template.instance().showUsersOffline.get() - # filter.status = { $ne: 'offline' } + # # unless Template.instance().showUsersOffline.get() + # # filter.status = { $ne: 'offline' } - filter.$and = [{ status: {$exists: true} }, { status: {$ne: 'offline'} }] + # filter.$and = [{ status: {$exists: true} }, { status: {$ne: 'offline'} }] - users = Meteor.users.find(filter, { sort: { name: 1 } } ).fetch() - ret.totalOnline = users.length - ret.users = users + # users = Meteor.users.find(filter, { sort: { name: 1 } } ).fetch() + # ret.totalOnline = users.length + # ret.users = users return ret diff --git a/client/views/app/sideNav/chatRoomItem.coffee b/client/views/app/sideNav/chatRoomItem.coffee index 2b13cd184e3..d87326a7e9e 100644 --- a/client/views/app/sideNav/chatRoomItem.coffee +++ b/client/views/app/sideNav/chatRoomItem.coffee @@ -11,8 +11,9 @@ Template.chatRoomItem.helpers userStatus: -> switch this.t when 'd' - uid = this.rid.replace Meteor.userId(), '' - return 'status-' + Session.get('user_' + uid + '_status') + username = this.rid.replace Meteor.user().username, '' + UserManager.addUser username + return 'status-' + Session.get('user_' + username + '_status') else return '' name: -> @@ -39,8 +40,8 @@ Template.chatRoomItem.helpers Template.chatRoomItem.rendered = -> if @data.t is 'd' - uid = @data.rid.replace Meteor.userId(), '' - UserManager.addUser uid + username = @data.rid.replace Meteor.user().username, '' + UserManager.addUser username if not (Router.current().params._id? and Router.current().params._id is this.data.rid) and (not this.data.ls? or moment(this.data.ls).add(1, 'days').startOf('day') < moment(this.data.ts).startOf('day')) KonchatNotification.newRoom(this.data.rid) diff --git a/client/views/app/sideNav/userStatus.coffee b/client/views/app/sideNav/userStatus.coffee index c5fcec5692f..76a834477d3 100644 --- a/client/views/app/sideNav/userStatus.coffee +++ b/client/views/app/sideNav/userStatus.coffee @@ -1,7 +1,8 @@ Template.userStatus.helpers myUserInfo: -> visualStatus = "online" - switch Session.get('user_' + Meteor.userId() + '_status') + username = Meteor.user().username + switch Session.get('user_' + username + '_status') when "away" visualStatus = t("userStatus.away") when "busy" @@ -9,11 +10,11 @@ Template.userStatus.helpers when "offline" visualStatus = t("userStatus.invisible") return { - name: Session.get('user_' + Meteor.userId() + '_name') - status: Session.get('user_' + Meteor.userId() + '_status') + name: Session.get('user_' + username + '_name') + status: Session.get('user_' + username + '_status') visualStatus: visualStatus _id: Meteor.userId() - username: Meteor.user().username + username: username } Template.userStatus.events diff --git a/client/views/app/userImageProfile.coffee b/client/views/app/userImageProfile.coffee index 4ba8babfb23..472123e4584 100644 --- a/client/views/app/userImageProfile.coffee +++ b/client/views/app/userImageProfile.coffee @@ -1,6 +1,3 @@ Template.userImageProfile.helpers - userName: -> - return Session.get('user_' + this._id + '_name') - userStatus: -> - return 'status-' + Session.get('user_' + this._id + '_status') + return 'status-' + Session.get('user_' + this + '_status') diff --git a/client/views/app/userImageProfile.html b/client/views/app/userImageProfile.html index 54ae1014969..28d30b3c156 100644 --- a/client/views/app/userImageProfile.html +++ b/client/views/app/userImageProfile.html @@ -1,8 +1,8 @@ diff --git a/server/publications.coffee b/server/publications.coffee index b5c3e81f6b0..21374024511 100644 --- a/server/publications.coffee +++ b/server/publications.coffee @@ -71,7 +71,7 @@ Meteor.publish 'allUsers', -> status: 1 }} -Meteor.publish 'selectiveUsers', (userIds) -> +Meteor.publish 'selectiveUsers', (usernames) -> unless @userId return @ready() @@ -79,7 +79,8 @@ Meteor.publish 'selectiveUsers', (userIds) -> self = @ - query = {} + query = + username: $exists: true options = fields: @@ -91,13 +92,13 @@ Meteor.publish 'selectiveUsers', (userIds) -> observer = cursor.observeChanges added: (id, record) -> - if userIds[id]? + if usernames[record.username]? self.added 'users', id, record changed: (id, record) -> - if userIds[id]? + if usernames[record.username]? self.changed 'users', id, record removed: (id) -> - if userIds[id]? + if usernames[record.username]? self.removed 'users', id @ready()