From 28a2365e0cd25baced797666eb306ce2af55285f Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 10 Oct 2025 16:41:40 -0500 Subject: [PATCH] Replace getPostThread in threadgate query --- .../dialogs/PostInteractionSettingsDialog.tsx | 10 +++++-- src/state/queries/threadgate/index.ts | 29 +++---------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/components/dialogs/PostInteractionSettingsDialog.tsx b/src/components/dialogs/PostInteractionSettingsDialog.tsx index 980ca594c6..5b9fc262dc 100644 --- a/src/components/dialogs/PostInteractionSettingsDialog.tsx +++ b/src/components/dialogs/PostInteractionSettingsDialog.tsx @@ -13,6 +13,7 @@ import isEqual from 'lodash.isequal' import {logger} from '#/logger' import {STALE} from '#/state/queries' import {useMyListsQuery} from '#/state/queries/my-lists' +import {useGetPost} from '#/state/queries/post' import { createPostgateQueryKey, getPostgateRecord, @@ -25,7 +26,6 @@ import { } from '#/state/queries/postgate/util' import { createThreadgateViewQueryKey, - getThreadgateView, type ThreadgateAllowUISetting, threadgateViewToAllowUISetting, useSetThreadgateAllowMutation, @@ -565,6 +565,7 @@ export function usePrefetchPostInteractionSettings({ }) { const queryClient = useQueryClient() const agent = useAgent() + const getPost = useGetPost() return React.useCallback(async () => { try { @@ -577,7 +578,10 @@ export function usePrefetchPostInteractionSettings({ }), queryClient.prefetchQuery({ queryKey: createThreadgateViewQueryKey(rootPostUri), - queryFn: () => getThreadgateView({agent, postUri: rootPostUri}), + queryFn: async () => { + const post = await getPost({uri: rootPostUri}) + return post.threadgate ?? null + }, staleTime: STALE.SECONDS.THIRTY, }), ]) @@ -586,5 +590,5 @@ export function usePrefetchPostInteractionSettings({ safeMessage: e.message, }) } - }, [queryClient, agent, postUri, rootPostUri]) + }, [queryClient, agent, postUri, rootPostUri, getPost]) } diff --git a/src/state/queries/threadgate/index.ts b/src/state/queries/threadgate/index.ts index e4b9241cd6..5a34eb3104 100644 --- a/src/state/queries/threadgate/index.ts +++ b/src/state/queries/threadgate/index.ts @@ -1,5 +1,5 @@ import { - AppBskyFeedDefs, + type AppBskyFeedDefs, AppBskyFeedThreadgate, AtUri, type BskyAgent, @@ -70,7 +70,7 @@ export function useThreadgateViewQuery({ postUri?: string initialData?: AppBskyFeedDefs.ThreadgateView } = {}) { - const agent = useAgent() + const getPost = useGetPost() return useQuery({ enabled: !!postUri, @@ -78,33 +78,12 @@ export function useThreadgateViewQuery({ placeholderData: initialData, staleTime: STALE.MINUTES.ONE, async queryFn() { - return getThreadgateView({ - agent, - postUri: postUri!, - }) + const post = await getPost({uri: postUri!}) + return post.threadgate ?? null }, }) } -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({ agent, postUri,