]> cat aescling's git repositories - mastodon.git/commitdiff
Fix crashes when connection drops
authorThibaut Girka <thib@sitedethib.com>
Tue, 15 Sep 2020 21:43:36 +0000 (23:43 +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 d1a0640cb8f3d1c5a07f7a6a7bf82b5f8e4ec645..d53fae35033be633e37a4b16d6978d37582e9e4c 100644 (file)
@@ -60,7 +60,7 @@ const mapStateToProps = state => ({
   numPending: state.getIn(['notifications', 'pendingItems'], ImmutableList()).size,
   notifCleaningActive: state.getIn(['notifications', 'cleaningMode']),
   lastReadId: state.getIn(['notifications', 'readMarkerId']),
-  canMarkAsRead: !state.getIn(['notifications', 'items']).isEmpty() && state.getIn(['notifications', 'readMarkerId']) !== '0' && compareId(state.getIn(['notifications', 'items']).first().get('id'), state.getIn(['notifications', 'readMarkerId'])) > 0,
+  canMarkAsRead: state.getIn(['notifications', 'readMarkerId']) !== '0' && getNotifications(state).some(item => item !== null && compareId(item.get('id'), state.getIn(['notifications', 'readMarkerId'])) > 0),
 });
 
 /* glitch */
index 122fd009ce23a829f738ee15b8326d7d0f8bd822..7820f524f0e270d464038f685eb432b1129f7c97 100644 (file)
@@ -110,8 +110,8 @@ const expandNormalizedNotifications = (state, notifications, next, isLoadingRece
     if (shouldCountUnreadNotifications(state)) {
       mutable.update('unread', unread => unread + items.count(item => compareId(item.get('id'), lastReadId) > 0));
     } else {
-      const mostRecentId = items.first().get('id');
-      if (compareId(lastReadId, mostRecentId) < 0) {
+      const mostRecent = items.find(item => item !== null);
+      if (mostRecent && compareId(lastReadId, mostRecent.get('id')) < 0) {
         mutable.set('lastReadId', mostRecentId);
       }
     }
@@ -299,7 +299,8 @@ export default function notifications(state = initialState, action) {
     return markAllForDelete(st, action.yes);
 
   case NOTIFICATIONS_MARK_AS_READ:
-    return recountUnread(state, state.get('items').first().get('id'));
+    const lastNotification = state.get('items').find(item => item !== null);
+    return lastNotification ? recountUnread(state, lastNotification.get('id')) : state;
 
   default:
     return state;