0
0
Fork 0

Use randomized setTimeout when fallback-polling and re-add since_id (#7522)

This commit is contained in:
Eugen Rochko 2018-05-18 02:32:35 +02:00 committed by GitHub
parent 1e02dc8715
commit dafd7afc5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 19 deletions

View file

@ -76,9 +76,14 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
const excludeTypesFromSettings = state => state.getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS();
export function expandNotifications({ maxId } = {}) {
const noOp = () => {};
export function expandNotifications({ maxId } = {}, done = noOp) {
return (dispatch, getState) => {
if (getState().getIn(['notifications', 'isLoading'])) {
const notifications = getState().get('notifications');
if (notifications.get('isLoading')) {
done();
return;
}
@ -87,6 +92,10 @@ export function expandNotifications({ maxId } = {}) {
exclude_types: excludeTypesFromSettings(getState()),
};
if (!maxId && notifications.get('items').size > 0) {
params.since_id = notifications.getIn(['items', 0]);
}
dispatch(expandNotificationsRequest());
api(getState).get('/api/v1/notifications', { params }).then(response => {
@ -97,8 +106,10 @@ export function expandNotifications({ maxId } = {}) {
dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null));
fetchRelatedRelationships(dispatch, response.data);
done();
}).catch(error => {
dispatch(expandNotificationsFail(error));
done();
});
};
};