From dd3229d9005dc9c10aac839bf48de8cb11ead3c7 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 29 Jan 2024 16:48:49 -0800 Subject: [PATCH] check if we are blocked when opening a profile, reset posts cache if we are --- src/state/queries/profile.ts | 19 ++++++++++++++++++- src/view/screens/Profile.tsx | 12 +++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 74be9933..cdfbf200 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -22,6 +22,7 @@ import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts' import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts' import {STALE} from '#/state/queries' import {track} from '#/lib/analytics/analytics' +import {queryClient} from '#/lib/react-query' export const RQKEY = (did: string) => ['profile', did] export const profilesQueryKey = (handles: string[]) => ['profiles', handles] @@ -375,8 +376,9 @@ function useProfileBlockMutation() { {subject: did, createdAt: new Date().toISOString()}, ) }, - onSuccess() { + onSuccess(_, {did}) { queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()}) + resetProfilePostsQueries(did, 1000) }, }) } @@ -394,6 +396,9 @@ function useProfileUnblockMutation() { rkey, }) }, + onSuccess(_, {did}) { + resetProfilePostsQueries(did, 1000) + }, }) } @@ -426,3 +431,15 @@ export function* findAllProfilesInQueryData( } } } + +export function resetProfilePostsQueries(did: string, timeout = 0) { + setTimeout(() => { + queryClient.resetQueries({ + predicate: query => + !!( + query.queryKey[0] === 'post-feed' && + (query.queryKey[1] as string)?.includes(did) + ), + }) + }, timeout) +} diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 7fc4d7a2..a0c8239f 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -23,7 +23,10 @@ import {useSetTitle} from 'lib/hooks/useSetTitle' import {combinedDisplayName} from 'lib/strings/display-names' import {FeedDescriptor} from '#/state/queries/post-feed' import {useResolveDidQuery} from '#/state/queries/resolve-uri' -import {useProfileQuery} from '#/state/queries/profile' +import { + resetProfilePostsQueries, + useProfileQuery, +} from '#/state/queries/profile' import {useProfileShadow} from '#/state/cache/profile-shadow' import {useSession} from '#/state/session' import {useModerationOpts} from '#/state/queries/preferences' @@ -74,6 +77,13 @@ export function ProfileScreen({route}: Props) { } }, [resolveError, refetchDid, refetchProfile]) + // When we open the profile, we want to reset the posts query if we are blocked. + React.useEffect(() => { + if (resolvedDid && profile?.viewer?.blockedBy) { + resetProfilePostsQueries(resolvedDid) + } + }, [profile?.viewer?.blockedBy, resolvedDid]) + if (isInitialLoadingDid || isInitialLoadingProfile || !moderationOpts) { return (