]> cat aescling's git repositories - mastodon.git/commitdiff
Fix potentially missing statuses when reconnecting to websocket (#17981)
authorClaire <claire.github-309c@sitedethib.com>
Thu, 7 Apr 2022 14:08:17 +0000 (16:08 +0200)
committerGitHub <noreply@github.com>
Thu, 7 Apr 2022 14:08:17 +0000 (16:08 +0200)
* Fix potentially missing statuses when reconnecting to websocket

* Add gap on reconnect rather than maintaining it constantly

app/javascript/mastodon/actions/timelines.js
app/javascript/mastodon/reducers/timelines.js

index 31ae09e4ac50139a28cc871ec2e3d2b10adee218..8bbaa104a0b6b5fe2c06ae2e6edf54dae0c4dee9 100644 (file)
@@ -184,6 +184,7 @@ export function connectTimeline(timeline) {
   return {
     type: TIMELINE_CONNECT,
     timeline,
+    usePendingItems: preferPendingItems,
   };
 };
 
index 53a644e47bafe006c3cd5ae429186359bb5b5198..d72109e696a805b6436c607288839b37d3958815 100644 (file)
@@ -171,6 +171,17 @@ const updateTop = (state, timeline, top) => {
   }));
 };
 
+const reconnectTimeline = (state, usePendingItems) => {
+  if (state.get('online')) {
+    return state;
+  }
+
+  return state.withMutations(mMap => {
+    mMap.update(usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items);
+    mMap.set('online', true);
+  });
+};
+
 export default function timelines(state = initialState, action) {
   switch(action.type) {
   case TIMELINE_LOAD_PENDING:
@@ -196,7 +207,7 @@ export default function timelines(state = initialState, action) {
   case TIMELINE_SCROLL_TOP:
     return updateTop(state, action.timeline, action.top);
   case TIMELINE_CONNECT:
-    return state.update(action.timeline, initialTimeline, map => map.set('online', true));
+    return state.update(action.timeline, initialTimeline, map => reconnectTimeline(map, action.usePendingItems));
   case TIMELINE_DISCONNECT:
     return state.update(
       action.timeline,