[SDK] Migrate discovery and post-thread queries to the appview client (#11355)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:14 +03:00
committed by GitHub
parent b804f267cc
commit 855457c9fa
12 changed files with 137 additions and 126 deletions
+16 -9
View File
@@ -1,4 +1,5 @@
import {useCallback, useMemo, useState} from 'react'
import {type AtUriString} from '@atproto/syntax'
import {useQuery, useQueryClient} from '@tanstack/react-query'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
@@ -27,10 +28,11 @@ import {
} from '#/state/queries/usePostThread/types'
import {getThreadgateRecord} from '#/state/queries/usePostThread/utils'
import * as views from '#/state/queries/usePostThread/views'
import {useAgent, useSession} from '#/state/session'
import {useAppviewClient, useSession} from '#/state/session'
import {useMergeThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
import {useBreakpoints} from '#/alf'
import {IS_WEB} from '#/env'
import {app} from '#/lexicons'
export * from '#/state/queries/usePostThread/context'
export {useUpdatePostThreadThreadgateQueryCache} from '#/state/queries/usePostThread/queryCache'
@@ -38,7 +40,7 @@ export * from '#/state/queries/usePostThread/types'
export function usePostThread({anchor}: {anchor?: string}) {
const qc = useQueryClient()
const agent = useAgent()
const client = useAppviewClient()
const {hasSession} = useSession()
const {gtPhone} = useBreakpoints()
const moderationOpts = useModerationOpts()
@@ -71,8 +73,8 @@ export function usePostThread({anchor}: {anchor?: string}) {
enabled: isThreadPreferencesLoaded && !!anchor && !!moderationOpts,
queryKey: postThreadQueryKey,
async queryFn(ctx) {
const {data} = await agent.app.bsky.unspecced.getPostThreadV2({
anchor: anchor!,
const data = await client.call(app.bsky.unspecced.getPostThreadV2, {
anchor: anchor! as AtUriString,
branchingFactor: view === 'linear' ? LINEAR_VIEW_BF : TREE_VIEW_BF,
below,
sort: sort,
@@ -93,18 +95,24 @@ export function usePostThread({anchor}: {anchor?: string}) {
ctx.meta.hasOtherReplies = true
}
/*
* The generated views type `threadgate.record` as an opaque lex map and
* brand at-uris, so the response is asserted to the exported result type
* here; the record swap-in below and every downstream consumer of the
* thread read that narrower contract.
*/
const result = {
thread: data.thread || [],
threadgate: data.threadgate,
hasOtherReplies: !!ctx.meta.hasOtherReplies,
}
} as UsePostThreadQueryResult
const record = getThreadgateRecord(result.threadgate)
if (result.threadgate && record) {
result.threadgate.record = record
}
return result as UsePostThreadQueryResult
return result
},
placeholderData() {
if (!anchor) return
@@ -161,10 +169,9 @@ export function usePostThread({anchor}: {anchor?: string}) {
enabled: additionalQueryEnabled,
queryKey: postThreadOtherQueryKey,
async queryFn() {
const {data} = await agent.app.bsky.unspecced.getPostThreadOtherV2({
anchor: anchor!,
return await client.call(app.bsky.unspecced.getPostThreadOtherV2, {
anchor: anchor! as AtUriString,
})
return data
},
})
const serverOtherThreadItems: ThreadItem[] = useMemo(() => {