Skip to content
Snippets Groups Projects
Commit 3ebd4e44 authored by Shpuld Shpludson's avatar Shpuld Shpludson
Browse files

document the 'mark-as-read-detection' system

parent a3e370e9
No related branches found
No related tags found
2 merge requests!12172.1.0 into master,!1164Fix: notifications fetcher double fetching on every tick
Pipeline #27935 passed
......@@ -27,17 +27,18 @@ const fetchAndUpdate = ({ store, credentials, older = false }) => {
}
const result = fetchNotifications({ store, args, older })
// load unread notifications repeatedly to provide consistency between browser tabs
// If there's any unread notifications, try fetch notifications since
// the newest read notification to check if any of the unread notifs
// have changed their 'seen' state (marked as read in another session), so
// we can update the state in this session to mark them as read as well.
// The normal maxId-check does not tell if older notifications have changed
const notifications = timelineData.data
const readNotifsIds = notifications.filter(n => n.seen).map(n => n.id)
if (readNotifsIds.length) {
const possibleMax = Math.max(...readNotifsIds)
if (possibleMax !== timelineData.maxId) {
args['since'] = possibleMax
fetchNotifications({ store, args, older })
}
const numUnseenNotifs = notifications.length - readNotifsIds.length
if (numUnseenNotifs > 0) {
args['since'] = Math.max(...readNotifsIds)
fetchNotifications({ store, args, older })
}
return result
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment