Remove getSuggestedFollowsByActor fallbacks and use recIdStr (#9988)

This commit is contained in:
DS Boyce
2026-03-12 16:57:38 -07:00
committed by GitHub
parent 35cb2bcf94
commit 0b6ff8000d
6 changed files with 148 additions and 336 deletions
+13 -13
View File
@@ -5,8 +5,8 @@ import {
type AppBskyActorGetProfiles,
type AppBskyActorProfile,
type AppBskyGraphGetFollows,
type AtpAgent,
AtUri,
type BskyAgent,
type ComAtprotoRepoUploadBlob,
type Un$Typed,
} from '@atproto/api'
@@ -203,19 +203,19 @@ export function useProfileUpdateMutation() {
(res => {
if (typeof newUserAvatar !== 'undefined') {
if (newUserAvatar === null && res.data.avatar) {
// url hasnt cleared yet
// url hasn't cleared yet
return false
} else if (res.data.avatar === profile.avatar) {
// url hasnt changed yet
// url hasn't changed yet
return false
}
}
if (typeof newUserBanner !== 'undefined') {
if (newUserBanner === null && res.data.banner) {
// url hasnt cleared yet
// url hasn't cleared yet
return false
} else if (res.data.banner === profile.banner) {
// url hasnt changed yet
// url hasn't changed yet
return false
}
}
@@ -231,10 +231,10 @@ export function useProfileUpdateMutation() {
},
async onSuccess(_, variables) {
// invalidate cache
queryClient.invalidateQueries({
void queryClient.invalidateQueries({
queryKey: RQKEY(variables.profile.did),
})
queryClient.invalidateQueries({
void queryClient.invalidateQueries({
queryKey: [profilesQueryKeyRoot, [variables.profile.did]],
})
await updateProfileVerificationCache({profile: variables.profile})
@@ -329,7 +329,7 @@ export function useProfileFollowMutationQueue(
}
if (finalFollowingUri) {
agent.app.bsky.graph
void agent.app.bsky.graph
.getSuggestedFollowsByActor({
actor: did,
})
@@ -474,7 +474,7 @@ function useProfileMuteMutation() {
await agent.mute(did)
},
onSuccess() {
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
},
})
}
@@ -487,7 +487,7 @@ function useProfileUnmuteMutation() {
await agent.unmute(did)
},
onSuccess() {
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
},
})
}
@@ -527,7 +527,7 @@ export function useProfileBlockMutationQueue(
updateProfileShadow(queryClient, did, {
blockingUri: finalBlockingUri,
})
queryClient.invalidateQueries({queryKey: [RQKEY_LIST_CONVOS]})
void queryClient.invalidateQueries({queryKey: [RQKEY_LIST_CONVOS]})
},
})
@@ -565,7 +565,7 @@ function useProfileBlockMutation() {
)
},
onSuccess(_, {did}) {
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
void queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
resetProfilePostsQueries(queryClient, did, 1000)
},
})
@@ -593,7 +593,7 @@ function useProfileUnblockMutation() {
}
async function whenAppViewReady(
agent: BskyAgent,
agent: AtpAgent,
actor: string,
fn: (res: AppBskyActorGetProfile.Response) => boolean,
) {
+6 -89
View File
@@ -2,107 +2,24 @@ import {
type AppBskyActorDefs,
type AppBskyActorGetSuggestions,
type AppBskyGraphGetSuggestedFollowsByActor,
moderateProfile,
} from '@atproto/api'
import {
type InfiniteData,
type QueryClient,
type QueryKey,
useInfiniteQuery,
useQuery,
} from '@tanstack/react-query'
import {
aggregateUserInterests,
createBskyTopicsHeader,
} from '#/lib/api/feed/utils'
import {getContentLanguages} from '#/state/preferences/languages'
import {STALE} from '#/state/queries'
import {usePreferencesQuery} from '#/state/queries/preferences'
import {useAgent, useSession} from '#/state/session'
import {useModerationOpts} from '../preferences/moderation-opts'
import {useAgent} from '#/state/session'
const suggestedFollowsQueryKeyRoot = 'suggested-follows'
const suggestedFollowsQueryKey = (options?: SuggestedFollowsOptions) => [
suggestedFollowsQueryKeyRoot,
options,
]
const suggestedFollowsByActorQueryKeyRoot = 'suggested-follows-by-actor'
const suggestedFollowsByActorQueryKey = (did: string) => [
export const suggestedFollowsByActorQueryKey = (did: string) => [
suggestedFollowsByActorQueryKeyRoot,
did,
]
type SuggestedFollowsOptions = {limit?: number; subsequentPageLimit?: number}
export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) {
const {currentAccount} = useSession()
const agent = useAgent()
const moderationOpts = useModerationOpts()
const {data: preferences} = usePreferencesQuery()
const limit = options?.limit || 25
return useInfiniteQuery<
AppBskyActorGetSuggestions.OutputSchema,
Error,
InfiniteData<AppBskyActorGetSuggestions.OutputSchema>,
QueryKey,
string | undefined
>({
enabled: !!moderationOpts && !!preferences,
staleTime: STALE.HOURS.ONE,
queryKey: suggestedFollowsQueryKey(options),
queryFn: async ({pageParam}) => {
const contentLangs = getContentLanguages().join(',')
const maybeDifferentLimit =
options?.subsequentPageLimit && pageParam
? options.subsequentPageLimit
: limit
const res = await agent.app.bsky.actor.getSuggestions(
{
limit: maybeDifferentLimit,
cursor: pageParam,
},
{
headers: {
...createBskyTopicsHeader(aggregateUserInterests(preferences)),
'Accept-Language': contentLangs,
},
},
)
res.data.actors = res.data.actors
.filter(
actor =>
!moderateProfile(actor, moderationOpts!).ui('profileList').filter,
)
.filter(actor => {
const viewer = actor.viewer
if (viewer) {
if (
viewer.following ||
viewer.muted ||
viewer.mutedByList ||
viewer.blockedBy ||
viewer.blocking
) {
return false
}
}
if (actor.did === currentAccount?.did) {
return false
}
return true
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
})
}
export function useSuggestedFollowsByActorQuery({
did,
enabled,
@@ -120,10 +37,10 @@ export function useSuggestedFollowsByActorQuery({
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
actor: did,
})
const suggestions = res.data.isFallback
? []
: res.data.suggestions.filter(profile => !profile.viewer?.following)
return {suggestions, recId: res.data.recId}
const suggestions = res.data.suggestions.filter(
profile => !profile.viewer?.following,
)
return {suggestions, recId: res.data.recIdStr}
},
enabled,
})