From 926595493dabf1531935379efaa16141571c3be6 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 5 Aug 2024 15:30:42 -0500 Subject: [PATCH] Enable un-hiding of replies --- src/state/queries/threadgate/index.ts | 2 ++ src/view/com/post-thread/PostThread.tsx | 7 +++-- src/view/com/util/forms/PostDropdownBtn.tsx | 34 +++++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/state/queries/threadgate/index.ts b/src/state/queries/threadgate/index.ts index cb63fcce2f..b72ab7de24 100644 --- a/src/state/queries/threadgate/index.ts +++ b/src/state/queries/threadgate/index.ts @@ -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, diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index bece2aa3de..a7be1f34c9 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -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, }) diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index 76fdaec658..64bff1281e 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -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 && ( { - toggleReplyVisibility({ - postUri: rootPostUri, - replyUri: postUri, - action: 'hide', - }) - }}> + label={ + isReplyHiddenByThreadgate + ? _(msg`Show reply for everyone`) + : _(msg`Hide reply for everyone`) + } + onPress={onToggleReplyVisibility}> - {_(msg`Hide reply for everyone`)} + {isReplyHiddenByThreadgate + ? _(msg`Show reply for everyone`) + : _(msg`Hide reply for everyone`)}