Fix up traversal metadata
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user