Only fetch threadgate for OP if they've started hiding replies
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user