Fix computation of isLastSibling and isLastChild to account for muted or
otherwise hidden replies
This commit is contained in:
@@ -193,7 +193,9 @@ export function sortAndAnnotateThreadItems(
|
|||||||
storeTraversalMetadata(metadatas, childMetadata)
|
storeTraversalMetadata(metadatas, childMetadata)
|
||||||
if (childParentMetadata) {
|
if (childParentMetadata) {
|
||||||
/*
|
/*
|
||||||
* Set this value before incrementing the parent's repliesIndexCounter
|
* Set this value before incrementing the parent's
|
||||||
|
* `repliesIndexCounter`, since `repliesIndexCounter` is
|
||||||
|
* 1-indexed and `replyIndex` is 0-indexed.
|
||||||
*/
|
*/
|
||||||
childMetadata!.replyIndex =
|
childMetadata!.replyIndex =
|
||||||
childParentMetadata.repliesIndexCounter
|
childParentMetadata.repliesIndexCounter
|
||||||
@@ -273,6 +275,14 @@ export function sortAndAnnotateThreadItems(
|
|||||||
metadata.replyIndex ===
|
metadata.replyIndex ===
|
||||||
metadata.parentMetadata.repliesIndexCounter - 1
|
metadata.parentMetadata.repliesIndexCounter - 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item is also the last "sibling" if its index matches the total
|
||||||
|
* number of replies we're actually able to render to the page.
|
||||||
|
*/
|
||||||
|
const isLastSiblingDueToMissingReplies =
|
||||||
|
metadata.replyIndex ===
|
||||||
|
metadata.parentMetadata.repliesSeenCounter - 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Item can also be the last "sibling" if we know we don't have a
|
* 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
|
* next item, OR if that next item's depth is less than this item's
|
||||||
@@ -280,6 +290,7 @@ export function sortAndAnnotateThreadItems(
|
|||||||
* item).
|
* item).
|
||||||
*/
|
*/
|
||||||
const isImplicitlyLastSibling =
|
const isImplicitlyLastSibling =
|
||||||
|
nextItem === undefined ||
|
||||||
metadata.nextItemDepth === undefined ||
|
metadata.nextItemDepth === undefined ||
|
||||||
metadata.nextItemDepth < metadata.depth
|
metadata.nextItemDepth < metadata.depth
|
||||||
|
|
||||||
@@ -287,7 +298,9 @@ export function sortAndAnnotateThreadItems(
|
|||||||
* Ok now we can set the last sibling state.
|
* Ok now we can set the last sibling state.
|
||||||
*/
|
*/
|
||||||
metadata.isLastSibling =
|
metadata.isLastSibling =
|
||||||
isLastSiblingByCounts || isImplicitlyLastSibling
|
isLastSiblingByCounts ||
|
||||||
|
isImplicitlyLastSibling ||
|
||||||
|
isLastSiblingDueToMissingReplies
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Item is the last "child" in a branch if there is no next item,
|
* Item is the last "child" in a branch if there is no next item,
|
||||||
@@ -296,6 +309,7 @@ export function sortAndAnnotateThreadItems(
|
|||||||
* of this item)
|
* of this item)
|
||||||
*/
|
*/
|
||||||
metadata.isLastChild =
|
metadata.isLastChild =
|
||||||
|
nextItem === undefined ||
|
||||||
metadata.nextItemDepth === undefined ||
|
metadata.nextItemDepth === undefined ||
|
||||||
metadata.nextItemDepth <= metadata.depth
|
metadata.nextItemDepth <= metadata.depth
|
||||||
|
|
||||||
|
|||||||
@@ -200,12 +200,20 @@ export type TraversalMetadata = {
|
|||||||
*
|
*
|
||||||
* After traversal, we can use this to calculate if we actually got all the
|
* After traversal, we can use this to calculate if we actually got all the
|
||||||
* replies we expected, or if some were blocked, etc.
|
* replies we expected, or if some were blocked, etc.
|
||||||
|
*
|
||||||
|
* Because this value is incremented startging from 0, it is 1-indexed. So to
|
||||||
|
* when comparing to the `replyIndex`, you'll need to subtract 1 from this
|
||||||
|
* value.
|
||||||
*/
|
*/
|
||||||
repliesSeenCounter: number
|
repliesSeenCounter: number
|
||||||
/**
|
/**
|
||||||
* The total number of replies to this post hydrated in this response. Used
|
* 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
|
* for populating the `replyIndex` of the post by referencing this value on
|
||||||
* the parent.
|
* the parent.
|
||||||
|
*
|
||||||
|
* Because this value is incremented startging from 0, it is 1-indexed. So to
|
||||||
|
* when comparing to the `replyIndex`, you'll need to subtract 1 from this
|
||||||
|
* value.
|
||||||
*/
|
*/
|
||||||
repliesIndexCounter: number
|
repliesIndexCounter: number
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user