about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-04-07 11:27:35 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-04-07 15:05:06 +0200
commited8a0bfbb80a759dc6944f599b89e52acb1e83b0 (patch)
tree70579b7050c39a90fbe35102d315f19410671541 /app/javascript
parent489f2508772a7214c219e66f8fa1aeea07ab6c08 (diff)
[Glitch] Fix older items possibly disappearing on timeline updates
Port 1b91359a4508b3068207ef4fd798a56549575591 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/flavours/glitch/reducers/timelines.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/javascript/flavours/glitch/reducers/timelines.js b/app/javascript/flavours/glitch/reducers/timelines.js
index b40e74c5b..29e02a864 100644
--- a/app/javascript/flavours/glitch/reducers/timelines.js
+++ b/app/javascript/flavours/glitch/reducers/timelines.js
@@ -66,13 +66,22 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
 
         // Then, try to find the furthest (if properly sorted, oldest) item in the timeline that
         // is newer than the most recent fetched one, as it delimits a section comprised of only
-        // items present in `newIds` (or that were deleted from the server, so should be removed
+        // items older or within `newIds` (or that were deleted from the server, so should be removed
         // anyway).
         // Stop the gap *after* that item.
         const firstIndex = oldIds.take(lastIndex).findLastIndex(id => id !== null && compareId(id, newIds.first()) > 0) + 1;
 
-        // Make sure we aren't inserting duplicates
-        let insertedIds = ImmutableOrderedSet(newIds).subtract(oldIds.take(firstIndex), oldIds.skip(lastIndex)).toList();
+        let insertedIds = ImmutableOrderedSet(newIds).withMutations(insertedIds => {
+          // It is possible, though unlikely, that the slice we are replacing contains items older
+          // than the elements we got from the API. Get them and add them back at the back of the
+          // slice.
+          const olderIds = oldIds.slice(firstIndex, lastIndex).filter(id => id !== null && compareId(id, newIds.last()) < 0);
+          insertedIds.union(olderIds);
+
+          // Make sure we aren't inserting duplicates
+          insertedIds.subtract(oldIds.take(firstIndex), oldIds.skip(lastIndex));
+        }).toList();
+
         // Finally, insert a gap marker if the data is marked as partial by the server
         if (isPartial && (firstIndex === 0 || oldIds.get(firstIndex - 1) !== null)) {
           insertedIds = insertedIds.unshift(null);