]> cat aescling's git repositories - mastodon.git/commitdiff
Only update read marker when giving focus/mounting column
authorThibaut Girka <thib@sitedethib.com>
Tue, 15 Sep 2020 18:54:26 +0000 (20:54 +0200)
committerThibG <thib@sitedethib.com>
Thu, 17 Sep 2020 13:22:56 +0000 (15:22 +0200)
app/javascript/flavours/glitch/features/notifications/index.js
app/javascript/flavours/glitch/reducers/notifications.js

index cef0a0d2ad090933688d7879d9909c4f74b7d046..1c8c68218618df44d7654115082ee2647fa3d0fe 100644 (file)
@@ -57,7 +57,7 @@ const mapStateToProps = state => ({
   hasMore: state.getIn(['notifications', 'hasMore']),
   numPending: state.getIn(['notifications', 'pendingItems'], ImmutableList()).size,
   notifCleaningActive: state.getIn(['notifications', 'cleaningMode']),
-  lastReadId: state.getIn(['notifications', 'lastReadId']),
+  lastReadId: state.getIn(['notifications', 'readMarkerId']),
 });
 
 /* glitch */
@@ -227,7 +227,7 @@ class Notifications extends React.PureComponent {
           accountId={item.get('account')}
           onMoveUp={this.handleMoveUp}
           onMoveDown={this.handleMoveDown}
-          unread={lastReadId && compareId(item.get('id'), lastReadId) > 0}
+          unread={lastReadId !== '0' && compareId(item.get('id'), lastReadId) > 0}
         />
       ));
     } else {
index 33f014dd1c17bd982d12e4d7f49106ad6261ad1c..7f6784eae6f51b9a7d1d096db48bebcadec6257e 100644 (file)
@@ -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));
     }