|
|
|
@ -11,33 +11,35 @@ const fetchAndUpdate = ({store, credentials, older = false}) => {
|
|
|
|
|
const rootState = store.rootState || store.state
|
|
|
|
|
const timelineData = rootState.statuses.notifications
|
|
|
|
|
|
|
|
|
|
args['timeline'] = 'notifications'
|
|
|
|
|
if (older) {
|
|
|
|
|
if (timelineData.minId !== Number.POSITIVE_INFINITY) {
|
|
|
|
|
args['until'] = timelineData.minId
|
|
|
|
|
}
|
|
|
|
|
return fetchNotifications({ store, args, older })
|
|
|
|
|
} else {
|
|
|
|
|
// fetch new notifications
|
|
|
|
|
if (timelineData.maxId !== Number.POSITIVE_INFINITY) {
|
|
|
|
|
args['since'] = timelineData.maxId
|
|
|
|
|
}
|
|
|
|
|
// # disabled until is_seen is impelented on the BE
|
|
|
|
|
// load unread notifications repeadedly to provide consistency between browser tabs
|
|
|
|
|
// const notifications = timelineData.data
|
|
|
|
|
// const unread = notifications.filter(n => !n.seen).map(n => n.id)
|
|
|
|
|
// if (!unread.length) {
|
|
|
|
|
// args['since'] = timelineData.maxId
|
|
|
|
|
// } else {
|
|
|
|
|
// args['since'] = Math.min(...unread) - 1
|
|
|
|
|
// if (timelineData.maxId !== Math.max(...unread)) {
|
|
|
|
|
// args['until'] = Math.max(...unread, args['since'] + 20)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
const result = fetchNotifications({ store, args, older })
|
|
|
|
|
|
|
|
|
|
// load unread notifications repeatedly to provide consistency between browser tabs
|
|
|
|
|
const notifications = timelineData.data
|
|
|
|
|
const unread = notifications.filter(n => !n.seen).map(n => n.id)
|
|
|
|
|
if (unread.length) {
|
|
|
|
|
args['since'] = Math.min(...unread)
|
|
|
|
|
fetchNotifications({ store, args, older })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args['timeline'] = 'notifications'
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fetchNotifications = ({ store, args, older }) => {
|
|
|
|
|
return apiService.fetchTimeline(args)
|
|
|
|
|
.then((notifications) => {
|
|
|
|
|
update({store, notifications, older})
|
|
|
|
|
update({ store, notifications, older })
|
|
|
|
|
return notifications
|
|
|
|
|
}, () => store.dispatch('setNotificationsError', { value: true }))
|
|
|
|
|
.catch(() => store.dispatch('setNotificationsError', { value: true }))
|
|
|
|
|