Revision b8c9069d
Added by matan werbner about 7 years ago
webpack/assets/javascripts/react_app/redux/actions/notifications/index.js | ||
---|---|---|
notificationsDrawer as sessionStorage
|
||
} from '../../../common/sessionStorage';
|
||
import API from '../../../API';
|
||
const getNotificationsInterval = 10000;
|
||
import { isNil } from 'lodash';
|
||
const defaultNotificationsPollingInterval = 10000;
|
||
const notificationsInterval = isNil(process.env.NOTIFICATIONS_POLLING) ?
|
||
defaultNotificationsPollingInterval :
|
||
process.env.NOTIFICATIONS_POLLING;
|
||
|
||
export const getNotifications = url => dispatch => {
|
||
new Promise((resolve, reject) => {
|
||
... | ... | |
document.visibilityState === 'visible' ||
|
||
document.visibilityState === 'prerender'
|
||
) {
|
||
API.get(url).then(response => {
|
||
dispatch({
|
||
type: NOTIFICATIONS_GET_NOTIFICATIONS,
|
||
payload: {
|
||
notifications: response.notifications
|
||
}
|
||
});
|
||
resolve();
|
||
}, () => reject());
|
||
API.get(url).then(
|
||
response => {
|
||
dispatch({
|
||
type: NOTIFICATIONS_GET_NOTIFICATIONS,
|
||
payload: {
|
||
notifications: response.notifications
|
||
}
|
||
});
|
||
resolve();
|
||
},
|
||
() => reject()
|
||
);
|
||
} else {
|
||
resolve();
|
||
}
|
||
return null;
|
||
}).then(
|
||
() => {
|
||
setTimeout(
|
||
() => dispatch(getNotifications(url)),
|
||
getNotificationsInterval
|
||
);
|
||
if (notificationsInterval) {
|
||
setTimeout(
|
||
() => dispatch(getNotifications(url)),
|
||
notificationsInterval
|
||
);
|
||
}
|
||
},
|
||
// error handling
|
||
() => {}
|
Also available in: Unified diff
Fixes #18438 - control notifications polling