about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2025-06-16 10:39:41 -0500
committerGitHub <noreply@github.com>2025-06-16 10:39:41 -0500
commitc2b71a6a9e668a8084c113825ba3ead58d1d300f (patch)
tree6365cca064b8fc56d93e2cc3b7389cdf7e5e38a7 /src
parent585dbebb693ac5799ee6cbedd918cf8fae01254d (diff)
downloadvoidsky-c2b71a6a9e668a8084c113825ba3ead58d1d300f.tar.zst
Fix v2 tree view bug caused by moderation settings (#8503)
* Use actual index, not seen index

* Handle edge case where last sibling is moderated
Diffstat (limited to 'src')
-rw-r--r--src/state/queries/usePostThread/traversal.ts32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/state/queries/usePostThread/traversal.ts b/src/state/queries/usePostThread/traversal.ts
index fbae4ecdb..124591125 100644
--- a/src/state/queries/usePostThread/traversal.ts
+++ b/src/state/queries/usePostThread/traversal.ts
@@ -265,12 +265,36 @@ export function sortAndAnnotateThreadItems(
               metadata.nextItemDepth = nextItem?.depth
 
             /*
-             * We can now officially calculate `isLastSibling` and `isLastChild`
-             * based on the actual data that we've seen.
+             * Item is the last "sibling" if we know for sure we're out of
+             * replies on the parent (even though this item itself may have its
+             * own reply branches).
              */
-            metadata.isLastSibling =
+            const isLastSiblingByCounts =
               metadata.replyIndex ===
-              metadata.parentMetadata.repliesSeenCounter - 1
+              metadata.parentMetadata.repliesIndexCounter - 1
+
+            /*
+             * Item can also be the last "sibling" if we know we don't have a
+             * next item, OR if that next item's depth is less than this item's
+             * depth (meaning it's a sibling of the parent, not a child of this
+             * item).
+             */
+            const isImplicitlyLastSibling =
+              metadata.nextItemDepth === undefined ||
+              metadata.nextItemDepth < metadata.depth
+
+            /*
+             * Ok now we can set the last sibling state.
+             */
+            metadata.isLastSibling =
+              isLastSiblingByCounts || isImplicitlyLastSibling
+
+            /*
+             * Item is the last "child" in a branch if there is no next item,
+             * or if the next item's depth is less than this item's depth (a
+             * sibling of the parent) or equal to this item's depth (a sibling
+             * of this item)
+             */
             metadata.isLastChild =
               metadata.nextItemDepth === undefined ||
               metadata.nextItemDepth <= metadata.depth