Skip to content
Snippets Groups Projects
Commit 9a090d16 authored by Gabriel Engel's avatar Gabriel Engel Committed by GitHub
Browse files

Merge pull request #5502 from wtsarchive/develop

Add REST API method to list online users in a room
parents 8a531b4e a43564de
No related merge requests found
......@@ -374,6 +374,39 @@ RocketChat.API.v1.addRoute('channels.list.joined', { authRequired: true }, {
}
});
RocketChat.API.v1.addRoute('channels.online', { authRequired: true }, {
get: function() {
const { query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, { t: 'c' });
const room = RocketChat.models.Rooms.findOne(ourQuery);
if (room == null) {
return RocketChat.API.v1.failure('Channel does not exists');
}
const online = RocketChat.models.Users.findUsersNotOffline({
fields: {
username: 1
}
}).fetch();
const onlineInRoom = [];
online.forEach(user => {
if (room.usernames.indexOf(user.username) !== -1) {
onlineInRoom.push({
_id: user._id,
username: user.username
});
}
});
return RocketChat.API.v1.success({
online: onlineInRoom
});
}
});
RocketChat.API.v1.addRoute('channels.open', { authRequired: true }, {
post: function() {
const findResult = findChannelById({ roomId: this.bodyParams.roomId, checkedArchived: false });
......
......@@ -282,6 +282,39 @@ RocketChat.API.v1.addRoute('groups.list', { authRequired: true }, {
}
});
RocketChat.API.v1.addRoute('groups.online', { authRequired: true }, {
get: function() {
const { query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, { t: 'p' });
const room = RocketChat.models.Rooms.findOne(ourQuery);
if (room == null) {
return RocketChat.API.v1.failure('Group does not exists');
}
const online = RocketChat.models.Users.findUsersNotOffline({
fields: {
username: 1
}
}).fetch();
const onlineInRoom = [];
online.forEach(user => {
if (room.usernames.indexOf(user.username) !== -1) {
onlineInRoom.push({
_id: user._id,
username: user.username
});
}
});
return RocketChat.API.v1.success({
online: onlineInRoom
});
}
});
RocketChat.API.v1.addRoute('groups.open', { authRequired: true }, {
post: function() {
const findResult = findPrivateGroupByIdOrName({ roomId: this.bodyParams.roomId, userId: this.userId, checkedArchived: false });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment