Only fetch threadgate for OP if they've started hiding replies

This commit is contained in:
Eric Bailey
2024-08-22 10:07:04 -07:00
parent 85d70fe3ef
commit 8bc36c1724
+10 -5
View File
@@ -31,6 +31,7 @@ import {usePreferencesQuery} from '#/state/queries/preferences'
import {useThreadgateRecordQuery} from '#/state/queries/threadgate' import {useThreadgateRecordQuery} from '#/state/queries/threadgate'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {useComposerControls} from '#/state/shell' import {useComposerControls} from '#/state/shell'
import {useThreadgateHiddenReplyUris} from '#/state/threadgate-hidden-replies'
import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender' import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender'
import {useMinimalShellFabTransform} from 'lib/hooks/useMinimalShellTransform' import {useMinimalShellFabTransform} from 'lib/hooks/useMinimalShellTransform'
import {useSetTitle} from 'lib/hooks/useSetTitle' import {useSetTitle} from 'lib/hooks/useSetTitle'
@@ -125,22 +126,26 @@ export function PostThread({uri}: {uri: string | undefined}) {
: undefined : undefined
const rootPostUri = replyRef ? replyRef.root.uri : rootPost?.uri const rootPostUri = replyRef ? replyRef.root.uri : rootPost?.uri
const {uris: hiddenReplyUris, recentlyUnhiddenUris} =
useThreadgateHiddenReplyUris()
const isOP = const isOP =
currentAccount && currentAccount &&
rootPostUri && rootPostUri &&
currentAccount?.did === new AtUri(rootPostUri).host currentAccount?.did === new AtUri(rootPostUri).host
const initialThreadgateRecord = rootPost?.threadgate?.record as const hasHiddenReplies = Boolean(
| AppBskyFeedThreadgate.Record hiddenReplyUris.size || recentlyUnhiddenUris.size,
| undefined )
const {data: threadgateRecord} = useThreadgateRecordQuery({ const {data: threadgateRecord} = useThreadgateRecordQuery({
/** /**
* If the user is the OP and the root post has a threadgate, we should load * 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 * the threadgate record. Otherwise, fallback to initialData, which is taken
* from the response from `getPostThread`. * from the response from `getPostThread`.
*/ */
enabled: Boolean(isOP && rootPostUri && initialThreadgateRecord), enabled: Boolean(isOP && rootPostUri && hasHiddenReplies),
postUri: rootPostUri, postUri: rootPostUri,
initialData: initialThreadgateRecord, initialData: rootPost?.threadgate?.record as
| AppBskyFeedThreadgate.Record
| undefined,
}) })
const moderationOpts = useModerationOpts() const moderationOpts = useModerationOpts()