check if we are blocked when opening a profile, reset posts cache if we are

zio/stable
Hailey 2024-01-29 16:48:49 -08:00
parent 4f28028569
commit dd3229d900
2 changed files with 29 additions and 2 deletions

View File

@ -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 {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
import {STALE} from '#/state/queries' import {STALE} from '#/state/queries'
import {track} from '#/lib/analytics/analytics' import {track} from '#/lib/analytics/analytics'
import {queryClient} from '#/lib/react-query'
export const RQKEY = (did: string) => ['profile', did] export const RQKEY = (did: string) => ['profile', did]
export const profilesQueryKey = (handles: string[]) => ['profiles', handles] export const profilesQueryKey = (handles: string[]) => ['profiles', handles]
@ -375,8 +376,9 @@ function useProfileBlockMutation() {
{subject: did, createdAt: new Date().toISOString()}, {subject: did, createdAt: new Date().toISOString()},
) )
}, },
onSuccess() { onSuccess(_, {did}) {
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()}) queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
resetProfilePostsQueries(did, 1000)
}, },
}) })
} }
@ -394,6 +396,9 @@ function useProfileUnblockMutation() {
rkey, 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)
}

View File

@ -23,7 +23,10 @@ import {useSetTitle} from 'lib/hooks/useSetTitle'
import {combinedDisplayName} from 'lib/strings/display-names' import {combinedDisplayName} from 'lib/strings/display-names'
import {FeedDescriptor} from '#/state/queries/post-feed' import {FeedDescriptor} from '#/state/queries/post-feed'
import {useResolveDidQuery} from '#/state/queries/resolve-uri' 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 {useProfileShadow} from '#/state/cache/profile-shadow'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {useModerationOpts} from '#/state/queries/preferences' import {useModerationOpts} from '#/state/queries/preferences'
@ -74,6 +77,13 @@ export function ProfileScreen({route}: Props) {
} }
}, [resolveError, refetchDid, refetchProfile]) }, [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) { if (isInitialLoadingDid || isInitialLoadingProfile || !moderationOpts) {
return ( return (
<CenteredView> <CenteredView>