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

This commit is contained in:
Shpuld Shpuldson 2020-07-01 17:55:42 +03:00
parent a3e370e9f8
commit 3ebd4e4429

View file

@ -27,17 +27,18 @@ const fetchAndUpdate = ({ store, credentials, older = false }) => {
} }
const result = fetchNotifications({ store, args, older }) 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 notifications = timelineData.data
const readNotifsIds = notifications.filter(n => n.seen).map(n => n.id) const readNotifsIds = notifications.filter(n => n.seen).map(n => n.id)
if (readNotifsIds.length) { const numUnseenNotifs = notifications.length - readNotifsIds.length
const possibleMax = Math.max(...readNotifsIds) if (numUnseenNotifs > 0) {
if (possibleMax !== timelineData.maxId) { args['since'] = Math.max(...readNotifsIds)
args['since'] = possibleMax
fetchNotifications({ store, args, older }) fetchNotifications({ store, args, older })
} }
}
return result return result
} }
} }