2 /*jslint node:true, unused:true */
5 var userService = require('gitter-web-users');
6 var troupeService = require('gitter-web-rooms/lib/troupe-service');
7 var collections = require('gitter-web-utils/lib/collections');
8 var presence = require('gitter-web-presence');
9 var _ = require('lodash');
11 var shutdown = require('shutdown');
13 var opts = require('yargs')
16 description: 'username of user to list presence for',
20 .alias('help', 'h').argv;
24 .findByUsername(opts.username)
25 .then(function(user) {
26 return presence.listAllSocketsForUser(user.id);
28 .then(function(socketIds) {
29 return presence.getSockets(socketIds);
31 .then(function(_sockets) {
32 //console.log(_sockets);
33 sockets = _.sortBy(_.values(_sockets), 'createdTime');
34 var troupeIds = _.pluck(sockets, 'troupeId');
35 return troupeService.findByIdsLean(troupeIds, { uri: 1 });
37 .then(function(troupes) {
38 // just modify it in place
39 var troupeHash = collections.indexById(troupes);
40 sockets.forEach(function(socket) {
41 if (troupeHash[socket.troupeId]) {
42 socket.troupe = troupeHash[socket.troupeId].uri;
44 // this is all the same anyway
49 console.log(_.countBy(sockets, function(socket) {
50 // isostring seems to contain milliseconds
51 return socket.createdTime.toISOString();
54 console.log('Total:', sockets.length);
56 .catch(function(err) {
57 console.error(err.stack);
60 shutdown.shutdownGracefully();