Gitter migration: Point people to app.gitter.im (rollout pt. 1)
[gitter.git] / modules / groups / lib / group-room-suggestions.js
blob47f5e7f66509c6c50ef455727f15bfff6f418065
1 'use strict';
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 })
17         .limit(10)
18         .lean()
19         .exec();
20     });
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 })
32         .limit(10)
33         .lean()
34         .exec();
35     });
38 module.exports = {
39   findUnjoinedRoomsInGroup: findUnjoinedRoomsInGroup,
40   findUnjoinedRoomsInGroups: findUnjoinedRoomsInGroups