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 {networkRetry} from '#/lib/async/retry'
import {STALE} from '#/state/queries'
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
import {
createThreadgateRecord,
@@ -32,6 +33,7 @@ export function useThreadgateRecordQuery({
enabled: !!postUri,
queryKey: createThreadgateRecordQueryKey(postUri || ''),
placeholderData: initialData,
staleTime: STALE.MINUTES.ONE,
async queryFn() {
return getThreadgateRecord({
agent,
+4 -3
View File
@@ -122,12 +122,13 @@ export function PostThread({
const rootPost = thread?.type === 'post' ? thread.post : undefined
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
const replyRef =
rootPost && AppBskyFeedPost.isRecord(rootPost.record)
? rootPost.record.reply
rootPostRecord && AppBskyFeedPost.isRecord(rootPostRecord)
? rootPostRecord.reply
: undefined
const rootPostUri = replyRef ? replyRef.root.uri : rootPost?.uri
const {data: threadgateRecord} = useThreadgateRecordQuery({
postUri: replyRef ? replyRef.root.uri : rootPost?.uri,
postUri: rootPostUri,
initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record,
})
+25 -9
View File
@@ -32,6 +32,7 @@ import {
useThreadMuteMutationQueue,
} from '#/state/queries/post'
import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate'
import {useThreadgateRecordQuery} from '#/state/queries/threadgate'
import {useSession} from '#/state/session'
import {getCurrentRoute} from 'lib/routes/helpers'
import {shareUrl} from 'lib/sharing'
@@ -122,6 +123,11 @@ let PostDropdownBtn = ({
const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri)
const isAuthor = postAuthor.did === currentAccount?.did
const {data: threadgate} = useThreadgateRecordQuery({
postUri: rootUri,
})
const isReplyHiddenByThreadgate = threadgate?.hiddenReplies?.includes(postUri)
const href = React.useMemo(() => {
const urip = new AtUri(postUri)
return makeProfileLink(postAuthor, 'post', urip.rkey)
@@ -248,6 +254,16 @@ let PostDropdownBtn = ({
[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
return (
@@ -403,16 +419,16 @@ let PostDropdownBtn = ({
{!isAuthor && !isPostHidden && rootPostUri && (
<Menu.Item
testID="postDropdownHideBtn"
label={_(msg`Hide reply for everyone`)}
onPress={() => {
toggleReplyVisibility({
postUri: rootPostUri,
replyUri: postUri,
action: 'hide',
})
}}>
label={
isReplyHiddenByThreadgate
? _(msg`Show reply for everyone`)
: _(msg`Hide reply for everyone`)
}
onPress={onToggleReplyVisibility}>
<Menu.ItemText>
{_(msg`Hide reply for everyone`)}
{isReplyHiddenByThreadgate
? _(msg`Show reply for everyone`)
: _(msg`Hide reply for everyone`)}
</Menu.ItemText>
<Menu.ItemIcon icon={EyeSlash} position="right" />
</Menu.Item>