From 92f58c872388962e4560a8b0ff1c644de66106cb Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 14 Oct 2025 15:52:52 -0500 Subject: [PATCH] The counters serve the same purpose, we only need to know the count of the actual replies rendered to the view in order to calculate the replyIndex --- src/state/queries/usePostThread/traversal.ts | 15 +++++------ src/state/queries/usePostThread/types.ts | 27 ++++++++------------ src/state/queries/usePostThread/utils.ts | 1 - 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/state/queries/usePostThread/traversal.ts b/src/state/queries/usePostThread/traversal.ts index 5c84e1c815..3680173384 100644 --- a/src/state/queries/usePostThread/traversal.ts +++ b/src/state/queries/usePostThread/traversal.ts @@ -135,11 +135,11 @@ export function sortAndAnnotateThreadItems( } else if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) { if (parentMetadata) { /* - * Set this value before incrementing the `repliesIndexCounter`, since - * `repliesIndexCounter` is 1-indexed and `replyIndex` is 0-indexed. + * Set this value before incrementing the `repliesSeenCounter` later + * on, since `repliesSeenCounter` is 1-indexed and `replyIndex` is + * 0-indexed. */ - metadata!.replyIndex = parentMetadata.repliesIndexCounter - parentMetadata.repliesIndexCounter += 1 + metadata!.replyIndex = parentMetadata.repliesSeenCounter } const post = views.threadPost({ @@ -194,12 +194,11 @@ export function sortAndAnnotateThreadItems( if (childParentMetadata) { /* * Set this value before incrementing the - * `repliesIndexCounter`, since `repliesIndexCounter` is - * 1-indexed and `replyIndex` is 0-indexed. + * `repliesSeenCounter` later on, since `repliesSeenCounter` + * is 1-indexed and `replyIndex` is 0-indexed. */ childMetadata!.replyIndex = - childParentMetadata.repliesIndexCounter - childParentMetadata.repliesIndexCounter += 1 + childParentMetadata.repliesSeenCounter } const childPost = views.threadPost({ diff --git a/src/state/queries/usePostThread/types.ts b/src/state/queries/usePostThread/types.ts index 785e865f34..3e84dbfc71 100644 --- a/src/state/queries/usePostThread/types.ts +++ b/src/state/queries/usePostThread/types.ts @@ -193,13 +193,14 @@ export type TraversalMetadata = { */ repliesUnhydrated: number /** - * The number of replies that have been seen so far in the traversal. - * Excludes replies that are moderated in some way, since those are not - * "seen" on first load. Use `repliesIndexCounter` for the total number of - * replies that were hydrated in the response. + * The number of replies that have been "seen" (actually able to be rendered) + * so far in the traversal. Excludes replies that are moderated in some way, + * since those are not "seen" on first load. * - * After traversal, we can use this to calculate if we actually got all the - * replies we expected, or if some were blocked, etc. + * We use this to compute the `replyIndex` values of the children of this + * parent. E.g. if a reply is not hydrated on the response, or is moderated + * in some way (including by the user), this value is not incremented. So + * this represents the _actual_ index of the reply in the rendered view. * * Note: this is a "counter", not an "index". Because this value is * incremented starting from 0, it is 1-indexed. So to when comparing to the @@ -207,17 +208,9 @@ export type TraversalMetadata = { */ repliesSeenCounter: number /** - * The total number of replies to this post hydrated in this response. Used - * for populating the `replyIndex` of the post by referencing this value on - * the parent. - * - * Note: this is a "counter", not an "index". Because this value is - * incremented starting from 0, it is 1-indexed. So to when comparing to the - * `replyIndex`, you'll need to subtract 1 from this value. - */ - repliesIndexCounter: number - /** - * The index-0-based index of this reply in the parent post's replies. + * The index-0-based index of this reply in the parent post's replies. This + * is computed from the `repliesSeenCounter` of the parent post, prior to it + * being incremented for this reply. */ replyIndex: number /** diff --git a/src/state/queries/usePostThread/utils.ts b/src/state/queries/usePostThread/utils.ts index 265bf7f5fb..be3be36b85 100644 --- a/src/state/queries/usePostThread/utils.ts +++ b/src/state/queries/usePostThread/utils.ts @@ -99,7 +99,6 @@ export function getTraversalMetadata({ repliesCount, repliesUnhydrated, repliesSeenCounter: 0, - repliesIndexCounter: 0, replyIndex: 0, skippedIndentIndices: new Set(), }