Compare commits

...

1 Commits

Author SHA1 Message Date
Eric Bailey 8bc36c1724 Only fetch threadgate for OP if they've started hiding replies 2024-08-22 10:07:04 -07:00
+10 -5
View File
@@ -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()