Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / serializers / rest / troupes / all-unread-item-count-strategy.js
blob6013f42fdb90d2e1f5591882042b57c241be49e5
1 'use strict';
3 var unreadItemService = require('gitter-web-unread-items');
5 function AllUnreadItemCountStrategy(options) {
6 this.userId = options.userId || options.currentUserId;
7 this.unreadCounts = null;
10 AllUnreadItemCountStrategy.prototype = {
11 preload: function(troupeIds) {
12 return unreadItemService
13 .getUserUnreadCountsForTroupeIds(this.userId, troupeIds.toArray())
14 .bind(this)
15 .then(function(result) {
16 this.unreadCounts = result;
17 });
20 map: function(id) {
21 var count = this.unreadCounts[id];
22 return count || 0;
25 name: 'AllUnreadItemCountStrategy'
28 module.exports = AllUnreadItemCountStrategy;