From 8bc36c1724dbb90170bb1ad64cb94337fd1f6682 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 22 Aug 2024 10:07:04 -0700 Subject: [PATCH] Only fetch threadgate for OP if they've started hiding replies --- src/view/com/post-thread/PostThread.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index 3757d76c6d..f02062396a 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -31,6 +31,7 @@ import {usePreferencesQuery} from '#/state/queries/preferences' import {useThreadgateRecordQuery} from '#/state/queries/threadgate' import {useSession} from '#/state/session' import {useComposerControls} from '#/state/shell' +import {useThreadgateHiddenReplyUris} from '#/state/threadgate-hidden-replies' import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender' import {useMinimalShellFabTransform} from 'lib/hooks/useMinimalShellTransform' import {useSetTitle} from 'lib/hooks/useSetTitle' @@ -125,22 +126,26 @@ export function PostThread({uri}: {uri: string | undefined}) { : undefined const rootPostUri = replyRef ? replyRef.root.uri : rootPost?.uri + const {uris: hiddenReplyUris, recentlyUnhiddenUris} = + useThreadgateHiddenReplyUris() const isOP = currentAccount && rootPostUri && currentAccount?.did === new AtUri(rootPostUri).host - const initialThreadgateRecord = rootPost?.threadgate?.record as - | AppBskyFeedThreadgate.Record - | undefined + const hasHiddenReplies = Boolean( + hiddenReplyUris.size || recentlyUnhiddenUris.size, + ) const {data: threadgateRecord} = useThreadgateRecordQuery({ /** * If the user is the OP and the root post has a threadgate, we should load * the threadgate record. Otherwise, fallback to initialData, which is taken * from the response from `getPostThread`. */ - enabled: Boolean(isOP && rootPostUri && initialThreadgateRecord), + enabled: Boolean(isOP && rootPostUri && hasHiddenReplies), postUri: rootPostUri, - initialData: initialThreadgateRecord, + initialData: rootPost?.threadgate?.record as + | AppBskyFeedThreadgate.Record + | undefined, }) const moderationOpts = useModerationOpts()