Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / serializers / rest / troupes / room-membership-strategy.js
bloba3cfdc1719814422632f9aa6cadf4afafc93b22e
1 'use strict';
3 var roomMembershipService = require('gitter-web-rooms/lib/room-membership-service');
4 var collections = require('gitter-web-utils/lib/collections');
6 function RoomMembershipStrategy(options) {
7 this.userId = options.userId || options.currentUserId;
8 this.nonMemberTroupeIds =
9 options.nonMemberTroupeIds && collections.hashArray(options.nonMemberTroupeIds);
10 this.predefinedValue = options.isRoomMember !== undefined;
11 this.isRoomMember = options.isRoomMember;
12 this.memberships = null;
15 RoomMembershipStrategy.prototype = {
16 preload: async function(troupeIds) {
17 // Shortcut logic
18 if (this.nonMemberTroupeIds || this.predefinedValue) {
19 return;
22 const memberTroupeIds = await roomMembershipService.findUserMembershipInRooms(
23 this.userId,
24 troupeIds.toArray()
27 this.memberships = collections.hashArray(memberTroupeIds);
30 map: function(id) {
31 if (this.predefinedValue) {
32 return this.isRoomMember;
35 if (this.nonMemberTroupeIds) {
36 return !this.nonMemberTroupeIds[id]; // Negate
39 return !!this.memberships[id];
42 name: 'AllUnreadItemCountStrategy'
45 module.exports = RoomMembershipStrategy;