aboutsummaryrefslogtreecommitdiff
path: root/src/services/notifications_fetcher
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2020-07-01 17:55:42 +0300
committerShpuld Shpuldson <shp@cock.li>2020-07-01 17:55:42 +0300
commit3ebd4e4429a9680046daeac2ed8753471365be9e (patch)
tree359a9986e1ed9638a7acc38d72b50f831c141b63 /src/services/notifications_fetcher
parenta3e370e9f816e3c98028bf82e8ac020b8e294466 (diff)
document the 'mark-as-read-detection' system
Diffstat (limited to 'src/services/notifications_fetcher')
-rw-r--r--src/services/notifications_fetcher/notifications_fetcher.service.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js
index 581931f5..c2552480 100644
--- a/src/services/notifications_fetcher/notifications_fetcher.service.js
+++ b/src/services/notifications_fetcher/notifications_fetcher.service.js
@@ -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
}
}