3 var Promise = require('bluebird');
4 var appEvents = require('gitter-web-appevents');
5 var restSerializer = require('../../serializers/rest-serializer');
6 var debug = require('debug')('gitter:app:live-collection-group-members');
7 var _ = require('lodash');
10 added: function(groupId, userIds) {
11 debug('Group %s: %s members added', groupId, userIds.length);
13 var singleUserId = userIds.length === 1 && userIds[0];
15 // TODO: custom serializations per user
17 .serializeObject(groupId, new restSerializer.GroupIdStrategy({ currentUserId: singleUserId }))
18 .then(function(serializedGroup) {
19 _.forEach(userIds, function(userId) {
20 var userUrl = '/user/' + userId + '/groups';
21 appEvents.dataChange2(userUrl, 'create', serializedGroup, 'group');
26 removed: function(groupId, userIds) {
27 _.forEach(userIds, function(userId) {
28 appEvents.dataChange2('/user/' + userId + '/groups', 'remove', { id: groupId }, 'group');
31 return Promise.resolve();