Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / serializers / rest / troupes / lurk-and-activity-for-user-strategy.js
blob9b372ab0b104efb89c786653e277a5bcb0101f65
1 'use strict';
3 var unreadItemService = require('gitter-web-unread-items');
4 var roomMembershipService = require('gitter-web-rooms/lib/room-membership-service');
5 var _ = require('lodash');
7 function LurkAndActivityForUserStrategy(options) {
8   this.currentUserId = options.currentUserId;
9   this.roomsWithLurk = null;
10   this.activity = null;
13 LurkAndActivityForUserStrategy.prototype = {
14   preload: function() {
15     return roomMembershipService
16       .findLurkingRoomIdsForUserId(this.currentUserId)
17       .bind(this)
18       .then(function(troupeIds) {
19         // Map the lurkers
20         this.roomsWithLurk = _.reduce(
21           troupeIds,
22           function(memo, troupeId) {
23             memo[troupeId] = true;
24             return memo;
25           },
26           {}
27         );
29         // Map the activity indicators
30         return unreadItemService.getActivityIndicatorForTroupeIds(troupeIds, this.currentUserId);
31       })
32       .then(function(values) {
33         this.activity = values;
34       });
35   },
37   mapLurkStatus: function(roomId) {
38     return this.roomsWithLurk[roomId] || false;
39   },
41   mapActivity: function(roomId) {
42     return this.activity[roomId];
43   },
45   name: 'LurkAndActivityForUserStrategy'
48 module.exports = LurkAndActivityForUserStrategy;