about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/reducers/notifications.js
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-09-15 20:54:26 +0200
committerThibG <thib@sitedethib.com>2020-09-17 15:22:56 +0200
commit94c290d7d2179adeb0437c00b571f62c41c7fd12 (patch)
tree8f7a88454905e9266220fec351a395575c7a82ed /app/javascript/flavours/glitch/reducers/notifications.js
parent145ed3797810cc652976a6198d6b23618e570bfd (diff)
Only update read marker when giving focus/mounting column
Diffstat (limited to 'app/javascript/flavours/glitch/reducers/notifications.js')
-rw-r--r--app/javascript/flavours/glitch/reducers/notifications.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js
index 33f014dd1..7f6784eae 100644
--- a/app/javascript/flavours/glitch/reducers/notifications.js
+++ b/app/javascript/flavours/glitch/reducers/notifications.js
@@ -39,6 +39,7 @@ const initialState = ImmutableMap({
   mounted: 0,
   unread: 0,
   lastReadId: '0',
+  readMarkerId: '0',
   isLoading: false,
   cleaningMode: false,
   isTabVisible: true,
@@ -183,6 +184,7 @@ const deleteMarkedNotifs = (state) => {
 const updateMounted = (state) => {
   state = state.update('mounted', count => count + 1);
   if (!shouldCountUnreadNotifications(state)) {
+    state = state.set('readMarkerId', state.get('lastReadId'));
     state = clearUnread(state);
   }
   return state;
@@ -191,6 +193,7 @@ const updateMounted = (state) => {
 const updateVisibility = (state, visibility) => {
   state = state.set('isTabVisible', visibility);
   if (!shouldCountUnreadNotifications(state)) {
+    state = state.set('readMarkerId', state.get('lastReadId'));
     state = clearUnread(state);
   }
   return state;
@@ -212,6 +215,10 @@ const recountUnread = (state, last_read_id) => {
       mutable.set('lastReadId', last_read_id);
     }
 
+    if (compareId(last_read_id, mutable.get('readMarkerId')) > 0) {
+      mutable.set('readMarkerId', last_read_id);
+    }
+
     if (state.get('unread') > 0 || shouldCountUnreadNotifications(state)) {
       mutable.set('unread', mutable.get('pendingItems').count(item => item !== null) + mutable.get('items').count(item => item && compareId(item.get('id'), last_read_id) > 0));
     }