3 var groupMembershipService = require('./group-membership-service');
4 var groupRoomFinder = require('./group-room-finder');
5 var persistence = require('gitter-web-persistence');
6 var Troupe = persistence.Troupe;
8 function findUnjoinedRoomsInGroup(groupId, userId) {
9 return groupMembershipService
10 .findRoomIdsForUserInGroup(groupId, userId)
11 .then(function(joinedRoomIds) {
12 var query = groupRoomFinder.queryForPublicRooms(groupId);
13 query.troupeId = { $nin: joinedRoomIds };
15 return Troupe.find(query)
16 .sort({ userCount: -1 })
23 function findUnjoinedRoomsInGroups(userId, groupIds) {
24 return groupMembershipService
25 .findRoomIdsForUserInGroups(userId, groupIds)
26 .then(function(joinedRoomIds) {
27 var query = groupRoomFinder.queryForPublicRoomsInGroupIds(groupIds);
28 query.troupeId = { $nin: joinedRoomIds };
30 return Troupe.find(query)
31 .sort({ userCount: -1 })
39 findUnjoinedRoomsInGroup: findUnjoinedRoomsInGroup,
40 findUnjoinedRoomsInGroups: findUnjoinedRoomsInGroups