3 var unreadItemService = require('gitter-web-unread-items');
4 var collections = require('gitter-web-utils/lib/collections');
5 var restSerializer = require('../../../serializers/rest-serializer');
8 id: 'aggregatedUnreadItem',
10 var userId = req.resourceUser.id;
12 return unreadItemService.getAllUnreadItemCounts(userId).then(function(counts) {
13 var troupeIds = counts.map(function(c) {
17 var strategy = new restSerializer.TroupeIdStrategy({
18 currentUserId: userId,
19 skipUnreadCounts: true
22 return restSerializer.serialize(troupeIds, strategy).then(function(troupes) {
23 var troupesIndexed = collections.indexById(troupes);
26 counts.forEach(function(count) {
27 var troupe = troupesIndexed[count.troupeId];
32 unreadItems: count.unreadItems,
33 mentions: count.mentions