3 var Promise = require('bluebird');
4 var assert = require('assert');
5 var roomMembershipFlags = require('./room-membership-flags');
6 var userDefaultFlagsService = require('./user-default-flags-service');
7 var roomMembershipService = require('./room-membership-service');
9 function updateDefaultModeForUser(user, mode, overrideExistingValues) {
10 assert(user, 'Expected user');
11 assert(mode, 'Expected mode');
13 var newDefaultFlags = roomMembershipFlags.getFlagsForMode(mode, true);
14 var userId = user._id;
16 // First, update the user...
17 return userDefaultFlagsService.setDefaultFlagsForUserId(userId, newDefaultFlags).then(function() {
18 user.defaultFlags = newDefaultFlags;
19 // Now, update the rooms
20 return roomMembershipService.updateRoomMembershipFlagsForUser(
23 overrideExistingValues
28 exports.updateDefaultModeForUser = Promise.method(updateDefaultModeForUser);