fix: don't expose post content on no-unauthenticated (#2584)

zio/stable
Mary 2024-01-23 06:55:51 +07:00 committed by GitHub
parent 7ca6ba2e1c
commit 55ad808785
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 4 deletions

View File

@ -36,11 +36,13 @@ import {Trans, msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {
UsePreferencesQueryResponse,
useModerationOpts,
usePreferencesQuery,
} from '#/state/queries/preferences'
import {useSession} from '#/state/session'
import {isNative} from '#/platform/detection'
import {logger} from '#/logger'
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
const MAINTAIN_VISIBLE_CONTENT_POSITION = {minIndexForVisible: 2}
@ -79,14 +81,30 @@ export function PostThread({
data: thread,
} = usePostThreadQuery(uri)
const {data: preferences} = usePreferencesQuery()
const rootPost = thread?.type === 'post' ? thread.post : undefined
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
const moderationOpts = useModerationOpts()
const isNoPwi = React.useMemo(() => {
const mod =
rootPost && moderationOpts
? moderatePost(rootPost, moderationOpts)
: undefined
const cause = mod?.content.cause
return cause
? cause.type === 'label' && cause.labelDef.id === '!no-unauthenticated'
: false
}, [rootPost, moderationOpts])
useSetTitle(
rootPost &&
`${sanitizeDisplayName(
rootPost && !isNoPwi
? `${sanitizeDisplayName(
rootPost.author.displayName || `@${rootPost.author.handle}`,
)}: "${rootPostRecord?.text}"`,
)}: "${rootPostRecord!.text}"`
: '',
)
useEffect(() => {
if (rootPost) {