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-19 14:30:09 +0200
committerThibG <thib@sitedethib.com>2020-09-19 15:01:46 +0200
commit787d5d728923393f12421a480b3c7aee789a11fe (patch)
treec89b8a0c11e162b7882c42a4f3330a4d7e56dfbd /app/javascript/flavours/glitch/reducers/notifications.js
parent312c936d5191b682d68b317ed7b6883aeee2c14e (diff)
Fix minor bugs
Diffstat (limited to 'app/javascript/flavours/glitch/reducers/notifications.js')
-rw-r--r--app/javascript/flavours/glitch/reducers/notifications.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js
index 67725b902..474ca3012 100644
--- a/app/javascript/flavours/glitch/reducers/notifications.js
+++ b/app/javascript/flavours/glitch/reducers/notifications.js
@@ -112,7 +112,7 @@ const expandNormalizedNotifications = (state, notifications, next, isLoadingRece
     } else {
       const mostRecent = items.find(item => item !== null);
       if (mostRecent && compareId(lastReadId, mostRecent.get('id')) < 0) {
-        mutable.set('lastReadId', mostRecentId);
+        mutable.set('lastReadId', mostRecent.get('id'));
       }
     }
 
@@ -129,7 +129,7 @@ const clearUnread = (state) => {
   state = state.set('unread', state.get('pendingItems').size);
   const lastNotification = state.get('items').find(item => item !== null);
   return state.set('lastReadId', lastNotification ? lastNotification.get('id') : '0');
-}
+};
 
 const updateTop = (state, top) => {
   state = state.set('top', top);
@@ -142,8 +142,9 @@ const updateTop = (state, top) => {
 };
 
 const deleteByStatus = (state, statusId) => {
+  const lastReadId = state.get('lastReadId');
+
   if (shouldCountUnreadNotifications(state)) {
-    const lastReadId = state.get('lastReadId');
     const deletedUnread = state.get('items').filter(item => item !== null && item.get('status') === statusId && compareId(item.get('id'), lastReadId) > 0);
     state = state.update('unread', unread => unread - deletedUnread.size);
   }
@@ -224,7 +225,7 @@ const recountUnread = (state, last_read_id) => {
       mutable.set('unread', mutable.get('pendingItems').count(item => item !== null) + mutable.get('items').count(item => item && compareId(item.get('id'), last_read_id) > 0));
     }
   });
-}
+};
 
 export default function notifications(state = initialState, action) {
   let st;