WIP sorta working op threads

This commit is contained in:
Eric Bailey
2025-10-14 20:29:43 -05:00
parent c428568b0c
commit 8f641f8a1b
4 changed files with 55 additions and 22 deletions
@@ -29,7 +29,6 @@ export const ThreadItemReadMore = memo(function ThreadItemReadMore({
const {_} = useLingui() const {_} = useLingui()
const isTreeView = view === 'tree' const isTreeView = view === 'tree'
const indent = Math.max(0, item.ui.indent - 1) const indent = Math.max(0, item.ui.indent - 1)
console.log({indent, id: item.ui.indent})
const spacers = isTreeView const spacers = isTreeView
? Array.from(Array(indent)).map((_, n: number) => { ? Array.from(Array(indent)).map((_, n: number) => {
+19 -12
View File
@@ -154,6 +154,7 @@ export function sortAndAnnotateThreadItems(
if (!post.isBlurred || skipModerationHandling) { if (!post.isBlurred || skipModerationHandling) {
const skip = const skip =
parentMetadata?.isPartOfOPThreadFromRoot && parentMetadata?.isPartOfOPThreadFromRoot &&
!parentMetadata.isEndOfOPThreadFromRoot &&
!metadata?.isPartOfOPThreadFromRoot !metadata?.isPartOfOPThreadFromRoot
if (skip) { if (skip) {
@@ -364,19 +365,25 @@ export function sortAndAnnotateThreadItems(
]) ])
/** /**
* If this is the last sibling, and the parent has no unhydrated * If the parent has no unhydrated replies that may require a
* replies, then we know we can skip an indent line. * `readMore`, we may be able to skip some of the indent lines.
*/ */
if ( if (metadata.parentMetadata.repliesUnhydrated <= 0) {
metadata.parentMetadata.repliesUnhydrated <= 0 && if (metadata.isLastSibling) {
metadata.isLastSibling /**
) { * We should definitely have a "last sibling" at this point.
/** *
* Depth is 2 more than the 0-index of the indent calculation * Note: depth is 2 more than the 0-index of the indent
* bc of how we render these. So instead of handling that in the * calculation bc of how we render these. So instead of
* component, we just adjust that back to 0-index here. * handling that in the component, we just adjust that back to
*/ * 0-index here.
metadata.skippedIndentIndices.add(item.depth - 2) */
metadata.skippedIndentIndices.add(item.depth - 2)
} else if (metadata.parentMetadata?.isEndOfOPThreadFromRoot) {
metadata.skippedIndentIndices.delete(
metadata.parentMetadata.indent - 1,
)
}
} }
} }
+3 -1
View File
@@ -170,10 +170,12 @@ export type TraversalMetadata = {
* of the tree are not considered part of the OP thread. * of the tree are not considered part of the OP thread.
*/ */
isPartOfOPThreadFromRoot: boolean isPartOfOPThreadFromRoot: boolean
isEndOfOPThreadFromRoot: boolean
/** /**
* Indicates if this item is the root post of the thread. * Indicates if this item is the root post of the thread.
*/ */
isRoot: boolean isRootPost: boolean
endOfOPThreadDepthOffset: number
/** /**
* The depth of the slice immediately following this one, if it exists. * The depth of the slice immediately following this one, if it exists.
*/ */
+33 -8
View File
@@ -63,18 +63,40 @@ export function getTraversalMetadata({
if (!AppBskyUnspeccedDefs.isThreadItemPost(item.value)) { if (!AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
throw new Error(`Expected thread item to be a post`) throw new Error(`Expected thread item to be a post`)
} }
const rootUri = getRootPostAtUri(item.value.post) const rootPostUri = getRootPostAtUri(item.value.post)
const rootAuthorDid = rootUri?.host const isRootPost = item.uri === rootPostUri?.toString()
const isRoot = item.uri === rootUri?.toString() const rootPostAuthorDid = rootPostUri?.host
const isPartOfOPThreadFromRoot = Boolean( const currentPostAuthorDid = item.value.post.author.did
item.value.post.author.did === rootAuthorDid && const currentPostIsByRootAuthor = currentPostAuthorDid === rootPostAuthorDid
(parentMetadata?.isRoot || parentMetadata?.isPartOfOPThreadFromRoot), const nextPostAuthorDid =
nextItem && AppBskyUnspeccedDefs.isThreadItemPost(nextItem.value)
? nextItem.value.post.author.did
: undefined
const parentIsPartOfOPThreadFromRoot = Boolean(
parentMetadata?.isRootPost || parentMetadata?.isPartOfOPThreadFromRoot,
) )
const isPartOfOPThreadFromRoot =
currentPostIsByRootAuthor && parentIsPartOfOPThreadFromRoot
const isEndOfOPThreadFromRoot =
isPartOfOPThreadFromRoot && currentPostAuthorDid !== nextPostAuthorDid
let indent = item.depth
if (isPartOfOPThreadFromRoot) {
indent = item.depth > 1 ? 1 : 0
} else if (parentMetadata?.endOfOPThreadDepthOffset) {
indent = item.depth - parentMetadata?.endOfOPThreadDepthOffset
}
// minus 1 so that the next reply under the end of the OP thread is indented by 1
const endOfOPThreadDepthOffset = isEndOfOPThreadFromRoot ? item.depth - 1 : 0
const repliesCount = item.value.post.replyCount || 0 const repliesCount = item.value.post.replyCount || 0
const repliesUnhydrated = item.value.moreReplies || 0 const repliesUnhydrated = item.value.moreReplies || 0
const metadata = { const metadata = {
depth: item.depth, depth: item.depth,
indent: isPartOfOPThreadFromRoot ? (item.depth < 1 ? 0 : 1) : item.depth, indent,
/* /*
* Unknown until after traversal * Unknown until after traversal
*/ */
@@ -90,7 +112,10 @@ export function getTraversalMetadata({
*/ */
isPartOfLastBranchFromDepth: item.depth === 1 ? 1 : undefined, isPartOfLastBranchFromDepth: item.depth === 1 ? 1 : undefined,
isPartOfOPThreadFromRoot, isPartOfOPThreadFromRoot,
isRoot, isEndOfOPThreadFromRoot,
isRootPost,
endOfOPThreadDepthOffset:
parentMetadata?.endOfOPThreadDepthOffset || endOfOPThreadDepthOffset,
nextItemDepth: nextItem?.depth, nextItemDepth: nextItem?.depth,
parentMetadata, parentMetadata,
prevItemDepth: prevItem?.depth, prevItemDepth: prevItem?.depth,