Fix up traversal metadata

This commit is contained in:
Eric Bailey
2025-05-27 20:50:04 -05:00
parent e5cc0c0ed2
commit 1f73c05195
5 changed files with 58 additions and 27 deletions
+24 -1
View File
@@ -2,10 +2,11 @@ import {
type AppBskyFeedDefs,
AppBskyFeedPost,
AppBskyFeedThreadgate,
type AppBskyUnspeccedGetPostThreadV2,
AppBskyUnspeccedGetPostThreadV2,
AtUri,
} from '@atproto/api'
import {type TraversalMetadata} from '#/state/queries/usePostThread/types'
import * as bsky from '#/types/bsky'
export function getThreadgateRecord(
@@ -31,3 +32,25 @@ export function getRootPostAtUri(post: AppBskyFeedDefs.PostView) {
}
}
}
export function getPostRecord(post: AppBskyFeedDefs.PostView) {
return post.record as AppBskyFeedPost.Record
}
export function getPostTraversalMetadata(
item: AppBskyUnspeccedGetPostThreadV2.ThreadItem,
): TraversalMetadata | undefined {
if (!AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(item.value)) return
const replyCount = item.value.post.replyCount || 0
const unhydratedReplies = item.value.moreReplies || 0
return {
depth: item.depth,
/**
* If the post has more than a single reply, and the total reply count
* minus the number of replies not present in the response is greater than
* 1, then we must have more than a single branch of replies present in the
* response, which can affect how we render tree view.
*/
hasBranchingReplies: replyCount > 1 && replyCount - unhydratedReplies > 1,
}
}