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
) {
18 if (this.nonMemberTroupeIds
|| this.predefinedValue
) {
22 const memberTroupeIds
= await roomMembershipService
.findUserMembershipInRooms(
27 this.memberships
= collections
.hashArray(memberTroupeIds
);
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
;