3 var Promise
= require('bluebird');
4 var presenceService
= require('gitter-web-presence');
5 var isNative
= require('./is-native');
8 * Figures out whether to use desktop notifications for this user
10 var determineDesktopNotifications
= Promise
.method(function(user
, req
) {
11 if (!user
) return true;
13 var agent
= req
.getParsedUserAgent();
14 var os
= agent
.os
.family
;
17 if (os
=== 'Mac OS X') {
19 } else if (os
.indexOf('Windows') === 0) {
21 } else if (os
.indexOf('Linux') === 0) {
26 return presenceService
27 .isUserConnectedWithClientType(user
.id
, clientType
)
28 .then(function(result
) {
36 function contextFromRequest(req
) {
38 var events
= req
.session
&& req
.session
.events
;
40 // Pass the feature toggles through to the client
42 if (req
.fflip
&& req
.fflip
.features
) {
43 features
= Object
.keys(req
.fflip
.features
).filter(function(featureKey
) {
44 return req
.fflip
.features
[featureKey
];
49 req
.session
.events
= [];
54 accessToken
: req
.accessToken
,
55 isNativeDesktopApp
: isNative(req
),
56 locale
: req
.i18n
.locales
[req
.i18n
.locale
],
64 return determineDesktopNotifications(user
, req
).then(function(desktopNotifications
) {
65 contextHash
.desktopNotifications
= desktopNotifications
;
70 module
.exports
= Promise
.method(contextFromRequest
);