Skip to content

Commit

Permalink
Merge pull request #42 from sscpac/feature/chat-locker-15
Browse files Browse the repository at this point in the history
Updated member list to show offline members also.
  • Loading branch information
bbrockman committed Aug 13, 2015
2 parents ee682d2 + f034000 commit 27389c4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 44 deletions.
20 changes: 9 additions & 11 deletions client/lib/RoomManager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Meteor.startup ->
subscription = null
msgStream = new Meteor.Stream 'messages'
deleteMsgStream = new Meteor.Stream 'delete-message'
onlineUsers = new ReactiveVar {}
allUsers = new ReactiveVar {}

Dep = new Tracker.Dependency

Expand Down Expand Up @@ -105,16 +105,14 @@ Meteor.startup ->
return room?.dom?

updateUserStatus = (user, status, utcOffset) ->
onlineUsersValue = onlineUsers.curValue
allUsersValue = allUsers.curValue
allUsersValue[user.username] =
firstName: user.profile.first_name
lastName: user.profile.last_name
name: user.name
status: user.status

if status is 'offline'
delete onlineUsersValue[user.username]
else
onlineUsersValue[user.username] =
status: status
utcOffset: utcOffset

onlineUsers.set onlineUsersValue
allUsers.set allUsersValue

open: open
close: close
Expand All @@ -124,4 +122,4 @@ Meteor.startup ->
msgStream: msgStream
openedRooms: openedRooms
updateUserStatus: updateUserStatus
onlineUsers: onlineUsers
allUsers: allUsers
2 changes: 1 addition & 1 deletion client/startup/usersObserve.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Meteor.startup ->
Meteor.users.find({}, { fields: { name: 1, username: 1, pictures: 1, status: 1, emails: 1, phone: 1, services: 1, utcOffset: 1 } }).observe
Meteor.users.find({}, { fields: { 'profile.first_name': 1, 'profile.last_name': 1, name: 1, username: 1, pictures: 1, status: 1, emails: 1, phone: 1, services: 1, utcOffset: 1 } }).observe
added: (user) ->
Session.set('user_' + user.username + '_status', user.status)
RoomManager.updateUserStatus user, user.status, user.utcOffset
Expand Down
5 changes: 2 additions & 3 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -2605,9 +2605,8 @@ a.github-fork {
text-overflow: ellipsis;
position: relative;
padding-left: 10px;
color: @secondary-font-color;
.calc(width,
~"100% - 45px");
//color: @secondary-font-color;
.calc(width, ~"100% - 45px");
}
}
a {
Expand Down
35 changes: 14 additions & 21 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Template.room.helpers
return roomData.u?._id is Meteor.userId() and roomData.t in ['c', 'p']

canPrivateMsg: ->
console.og 'room.helpers canPrivateMsg' if window.rocketDebug
console.log 'room.helpers canPrivateMsg' if window.rocketDebug
return Meteor.userId() isnt this.username

roomNameEdit: ->
Expand Down Expand Up @@ -182,33 +182,25 @@ Template.room.helpers
status = Session.get 'user_' + username + '_status'
if status in ['online', 'away', 'busy']
return {username: username, status: status}
return
return {username: username, status: 'offline'}

roomUsers: ->
room = ChatRoom.findOne(this._id, { reactive: false })
users = []
onlineUsers = RoomManager.onlineUsers.get()
allUsers = RoomManager.allUsers.get()

for username in room?.usernames or []
if onlineUsers[username]?
utcOffset = onlineUsers[username]?.utcOffset
if utcOffset?
if utcOffset > 0
utcOffset = "+#{utcOffset}"
users.push
firstName: allUsers[username]?.firstName
lastName: allUsers[username]?.lastName
name: allUsers[username]?.name
username: username
status: allUsers[username]?.status

utcOffset = "(UTC #{utcOffset})"

users.push
username: username
status: onlineUsers[username]?.status
utcOffset: utcOffset

users = _.sortBy users, 'username'
users = _.sortBy users, 'lastName'

ret =
_id: this._id
total: room.usernames.length
totalOnline: users.length
users: users

return ret
Expand Down Expand Up @@ -281,6 +273,7 @@ Template.room.helpers
# this is to make "bannerData" itself reactive by having it depend directly on the room data.
# Then, since that data gets synchronized with the server, the template will be reprocessed
# when the data changes.

roomData = Session.get('roomData' + this._id)
Template.instance().accessPermissions.set roomData?.accessPermissions
return Template.instance().accessPermissions
Expand Down Expand Up @@ -412,15 +405,15 @@ Template.room.events

'click .user-view nav .pvt-msg': (e) ->
console.log 'room click .user-view nav .pvt-msg' if window.rocketDebug
# determine if we're creating new room or opening existing room. DM uses
# determine if we're creating new room or opening existing room. DM uses
# usernames for room id
me = Meteor.user().username
to = Session.get('showUserInfo')
rid = [me, to].sort().join('')
if ChatSubscription.findOne({rid:rid})
# conversation already exists
FlowRouter.go('room', {_id: rid})
else
else
# close side nav if it's open
if SideNav.flexStatus
SideNav.setFlex null
Expand Down Expand Up @@ -579,7 +572,7 @@ Template.room.onCreated ->
self = this
# this.scrollOnBottom = true
# this.typing = new msgTyping this.data._id
this.showUsersOffline = new ReactiveVar false
this.showUsersOffline = new ReactiveVar true
this.atBottom = true
this.accessPermissions = new ReactiveVar []

Expand Down
10 changes: 3 additions & 7 deletions client/views/app/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,14 @@ <h2>
<div class="list-view{{#if $.Session.get 'showUserInfo'}} -hidden{{/if}}">
{{#with roomUsers}}
<div class="status">
<h2>{{_ "Members_List"}}</h2> {{!--
<p>
{{{_ "Showing_online_users" total_online=totalOnline total=total}}}
<button class="see-all">{{seeAll}}</button>
</p>--}}
<h2>{{_ "Members_List"}}</h2>
</div>
<ul class='list clearfix lines'>
{{#each users}}
<li class='user-image user-card-room status-{{status}}'>
<a data-username="{{username}}" tabindex="0" title="{{username}}">
<a data-username="{{username}}" tabindex="0" title="{{username}}" class="status-{{status}}">
{{> avatar username=username}}
<p>{{username}} {{utcOffset}}</p>
<p class="status-{{status}}">{{firstName}} {{lastName}}</p>
</a>
</li>
{{/each}}
Expand Down
11 changes: 10 additions & 1 deletion server/publications/userData.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ Meteor.publish 'userData', ->

console.log '[publish] userData'.green

Meteor.users.find this.userId,
###
Please note this returns the information for all users back to the client.
Make sure to not add any more fields that are sensitive like access inside
the profile or the entire profile object which would contain the access.
###
Meteor.users.find {},
fields:
name: 1
'profile.first_name': 1
'profile.last_name': 1
username: 1
emails: 1
phone: 1
status: 1
statusDefault: 1
statusConnection: 1
Expand Down

0 comments on commit 27389c4

Please sign in to comment.