Skip to content

Commit

Permalink
Add API method to list online users in a room
Browse files Browse the repository at this point in the history
  • Loading branch information
wtsarchive committed Apr 20, 2016
1 parent 7d3e848 commit 5ac497b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/restapi/restapi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ Api.addRoute 'rooms/:id/send', authRequired: true,
Meteor.call('sendMessage', {msg: this.bodyParams.msg, rid: @urlParams.id} )
status: 'success' #need to handle error

# get list of online users in a room
Api.addRoute 'rooms/:id/online', authRequired: true,
get: ->
room = RocketChat.models.Rooms.findOneById @urlParams.id
online = RocketChat.models.Users.findUsersNotOffline(fields:
username: 1
status: 1).fetch()
onlineInRoom = []
for user, i in online
if room.usernames.indexOf(user.username) != -1
onlineInRoom.push user.username

status: 'success', online: onlineInRoom

# validate an array of users
Api.testapiValidateUsers = (users) ->
Expand Down

0 comments on commit 5ac497b

Please sign in to comment.