Enable un-hiding of replies

This commit is contained in:
Eric Bailey
2024-08-05 15:30:42 -05:00
parent 8c1c149d5d
commit 926595493d
3 changed files with 31 additions and 12 deletions
+2
View File
@@ -2,6 +2,7 @@ import {AppBskyFeedThreadgate, AtUri, BskyAgent} from '@atproto/api'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
import {STALE} from '#/state/queries'
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types' import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
import { import {
createThreadgateRecord, createThreadgateRecord,
@@ -32,6 +33,7 @@ export function useThreadgateRecordQuery({
enabled: !!postUri, enabled: !!postUri,
queryKey: createThreadgateRecordQueryKey(postUri || ''), queryKey: createThreadgateRecordQueryKey(postUri || ''),
placeholderData: initialData, placeholderData: initialData,
staleTime: STALE.MINUTES.ONE,
async queryFn() { async queryFn() {
return getThreadgateRecord({ return getThreadgateRecord({
agent, agent,
+4 -3
View File
@@ -122,12 +122,13 @@ export function PostThread({
const rootPost = thread?.type === 'post' ? thread.post : undefined const rootPost = thread?.type === 'post' ? thread.post : undefined
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
const replyRef = const replyRef =
rootPost && AppBskyFeedPost.isRecord(rootPost.record) rootPostRecord && AppBskyFeedPost.isRecord(rootPostRecord)
? rootPost.record.reply ? rootPostRecord.reply
: undefined : undefined
const rootPostUri = replyRef ? replyRef.root.uri : rootPost?.uri
const {data: threadgateRecord} = useThreadgateRecordQuery({ const {data: threadgateRecord} = useThreadgateRecordQuery({
postUri: replyRef ? replyRef.root.uri : rootPost?.uri, postUri: rootPostUri,
initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record, initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record,
}) })
+25 -9
View File
@@ -32,6 +32,7 @@ import {
useThreadMuteMutationQueue, useThreadMuteMutationQueue,
} from '#/state/queries/post' } from '#/state/queries/post'
import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate' import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate'
import {useThreadgateRecordQuery} from '#/state/queries/threadgate'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {getCurrentRoute} from 'lib/routes/helpers' import {getCurrentRoute} from 'lib/routes/helpers'
import {shareUrl} from 'lib/sharing' import {shareUrl} from 'lib/sharing'
@@ -122,6 +123,11 @@ let PostDropdownBtn = ({
const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri) const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri)
const isAuthor = postAuthor.did === currentAccount?.did const isAuthor = postAuthor.did === currentAccount?.did
const {data: threadgate} = useThreadgateRecordQuery({
postUri: rootUri,
})
const isReplyHiddenByThreadgate = threadgate?.hiddenReplies?.includes(postUri)
const href = React.useMemo(() => { const href = React.useMemo(() => {
const urip = new AtUri(postUri) const urip = new AtUri(postUri)
return makeProfileLink(postAuthor, 'post', urip.rkey) return makeProfileLink(postAuthor, 'post', urip.rkey)
@@ -248,6 +254,16 @@ let PostDropdownBtn = ({
[navigation, postUri], [navigation, postUri],
) )
const onToggleReplyVisibility = React.useCallback(() => {
if (!rootPostUri) return
toggleReplyVisibility({
postUri: rootPostUri,
replyUri: postUri,
action: isReplyHiddenByThreadgate ? 'show' : 'hide',
})
}, [isReplyHiddenByThreadgate, rootPostUri, postUri, toggleReplyVisibility])
const canEmbed = isWeb && gtMobile && !hideInPWI const canEmbed = isWeb && gtMobile && !hideInPWI
return ( return (
@@ -403,16 +419,16 @@ let PostDropdownBtn = ({
{!isAuthor && !isPostHidden && rootPostUri && ( {!isAuthor && !isPostHidden && rootPostUri && (
<Menu.Item <Menu.Item
testID="postDropdownHideBtn" testID="postDropdownHideBtn"
label={_(msg`Hide reply for everyone`)} label={
onPress={() => { isReplyHiddenByThreadgate
toggleReplyVisibility({ ? _(msg`Show reply for everyone`)
postUri: rootPostUri, : _(msg`Hide reply for everyone`)
replyUri: postUri, }
action: 'hide', onPress={onToggleReplyVisibility}>
})
}}>
<Menu.ItemText> <Menu.ItemText>
{_(msg`Hide reply for everyone`)} {isReplyHiddenByThreadgate
? _(msg`Show reply for everyone`)
: _(msg`Hide reply for everyone`)}
</Menu.ItemText> </Menu.ItemText>
<Menu.ItemIcon icon={EyeSlash} position="right" /> <Menu.ItemIcon icon={EyeSlash} position="right" />
</Menu.Item> </Menu.Item>