Replace getPostThread in threadgate query

This commit is contained in:
Eric Bailey
2025-10-10 16:41:40 -05:00
parent c8ded6291f
commit 28a2365e0c
2 changed files with 11 additions and 28 deletions
@@ -13,6 +13,7 @@ import isEqual from 'lodash.isequal'
import {logger} from '#/logger' import {logger} from '#/logger'
import {STALE} from '#/state/queries' import {STALE} from '#/state/queries'
import {useMyListsQuery} from '#/state/queries/my-lists' import {useMyListsQuery} from '#/state/queries/my-lists'
import {useGetPost} from '#/state/queries/post'
import { import {
createPostgateQueryKey, createPostgateQueryKey,
getPostgateRecord, getPostgateRecord,
@@ -25,7 +26,6 @@ import {
} from '#/state/queries/postgate/util' } from '#/state/queries/postgate/util'
import { import {
createThreadgateViewQueryKey, createThreadgateViewQueryKey,
getThreadgateView,
type ThreadgateAllowUISetting, type ThreadgateAllowUISetting,
threadgateViewToAllowUISetting, threadgateViewToAllowUISetting,
useSetThreadgateAllowMutation, useSetThreadgateAllowMutation,
@@ -565,6 +565,7 @@ export function usePrefetchPostInteractionSettings({
}) { }) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const agent = useAgent() const agent = useAgent()
const getPost = useGetPost()
return React.useCallback(async () => { return React.useCallback(async () => {
try { try {
@@ -577,7 +578,10 @@ export function usePrefetchPostInteractionSettings({
}), }),
queryClient.prefetchQuery({ queryClient.prefetchQuery({
queryKey: createThreadgateViewQueryKey(rootPostUri), queryKey: createThreadgateViewQueryKey(rootPostUri),
queryFn: () => getThreadgateView({agent, postUri: rootPostUri}), queryFn: async () => {
const post = await getPost({uri: rootPostUri})
return post.threadgate ?? null
},
staleTime: STALE.SECONDS.THIRTY, staleTime: STALE.SECONDS.THIRTY,
}), }),
]) ])
@@ -586,5 +590,5 @@ export function usePrefetchPostInteractionSettings({
safeMessage: e.message, safeMessage: e.message,
}) })
} }
}, [queryClient, agent, postUri, rootPostUri]) }, [queryClient, agent, postUri, rootPostUri, getPost])
} }
+4 -25
View File
@@ -1,5 +1,5 @@
import { import {
AppBskyFeedDefs, type AppBskyFeedDefs,
AppBskyFeedThreadgate, AppBskyFeedThreadgate,
AtUri, AtUri,
type BskyAgent, type BskyAgent,
@@ -70,7 +70,7 @@ export function useThreadgateViewQuery({
postUri?: string postUri?: string
initialData?: AppBskyFeedDefs.ThreadgateView initialData?: AppBskyFeedDefs.ThreadgateView
} = {}) { } = {}) {
const agent = useAgent() const getPost = useGetPost()
return useQuery({ return useQuery({
enabled: !!postUri, enabled: !!postUri,
@@ -78,33 +78,12 @@ export function useThreadgateViewQuery({
placeholderData: initialData, placeholderData: initialData,
staleTime: STALE.MINUTES.ONE, staleTime: STALE.MINUTES.ONE,
async queryFn() { async queryFn() {
return getThreadgateView({ const post = await getPost({uri: postUri!})
agent, return post.threadgate ?? null
postUri: postUri!,
})
}, },
}) })
} }
export async function getThreadgateView({
agent,
postUri,
}: {
agent: BskyAgent
postUri: string
}) {
const {data} = await agent.app.bsky.feed.getPostThread({
uri: postUri!,
depth: 0,
})
if (AppBskyFeedDefs.isThreadViewPost(data.thread)) {
return data.thread.post.threadgate ?? null
}
return null
}
export async function getThreadgateRecord({ export async function getThreadgateRecord({
agent, agent,
postUri, postUri,