3 var Promise
= require('bluebird');
4 var StatusError
= require('statuserror');
5 var roomMembershipService
= require('gitter-web-rooms/lib/room-membership-service');
6 var userDefaultFlagsService
= require('gitter-web-rooms/lib/user-default-flags-service');
7 var userRoomModeUpdateService
= require('gitter-web-rooms/lib/user-room-mode-update-service');
9 function generateResponse(userId
, troupeId
) {
11 roomMembershipService
.getMembershipDetails(userId
, troupeId
),
12 userDefaultFlagsService
.getDefaultFlagDetailsForUserId(userId
),
13 function(details
, defaults
) {
14 if (!details
) throw new StatusError(404);
17 push
: details
.mode
, // REMOVE THIS
19 lurk
: details
.lurk
, // ALSO deprecated
21 unread
: details
.unread
,
22 activity
: details
.activity
,
23 mention
: details
.mention
,
24 announcement
: details
.announcement
,
25 desktop
: details
.desktop
,
26 mobile
: details
.mobile
,
28 default: details
.default,
29 defaultSettings
: defaults
35 * TODO: REMOVE THIS WHOLE RESOURCE AND UPDATE THIS VIA THE USER TROUPE
42 var userId
= req
.resourceUser
.id
;
43 var troupeId
= req
.params
.userTroupeId
;
44 var setting
= req
.params
.setting
;
46 if (setting
!== 'notifications') throw new StatusError(404);
48 return generateResponse(userId
, troupeId
);
51 update: function(req
) {
52 var userId
= req
.resourceUser
.id
;
53 var troupeId
= req
.params
.userTroupeId
;
54 var setting
= req
.params
.setting
;
56 if (setting
!== 'notifications') throw new StatusError(404);
58 var settings
= req
.body
;
59 var mode
= settings
&& (settings
.mode
|| settings
.push
);
61 if (!mode
) throw new StatusError(400, 'Illegal notifications mode');
62 return userRoomModeUpdateService
63 .setModeForUserInRoom(req
.resourceUser
, troupeId
, mode
)
65 return generateResponse(userId
, troupeId
);