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 23:43:36 +0200
committerThibG <thib@sitedethib.com>2020-09-17 15:22:56 +0200
commit60eebc6cc4d62479b23c2148c76172c0b3458629 (patch)
tree6d1cae74c1204c97aeb4ce5b890d57d73ec146a9 /app/javascript/flavours/glitch/reducers/notifications.js
parentf1c0cf98061eee5eb6130b167d033c851ee58f14 (diff)
Fix crashes when connection drops
Diffstat (limited to 'app/javascript/flavours/glitch/reducers/notifications.js')
-rw-r--r--app/javascript/flavours/glitch/reducers/notifications.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/javascript/flavours/glitch/reducers/notifications.js b/app/javascript/flavours/glitch/reducers/notifications.js
index 122fd009c..7820f524f 100644
--- a/app/javascript/flavours/glitch/reducers/notifications.js
+++ b/app/javascript/flavours/glitch/reducers/notifications.js
@@ -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;