300a50b69a
Phase 3 tasks 3-7 (parallel wave): composer/post pipeline on pdsClient/appviewClient with structural+instance blob guards and a golden CID fixture test; chat Convo/EventBus/queries on the dedicated chat client; preferences sugar to SDK actions on the PDS client; remaining state/queries producers (usePostThread unspecced flip, video scoped-token clients, notifications, starter packs, lists) to client.call; UI runtime sweep (AtUri from @atproto/syntax, moderation fns from @bsky.app/sdk/moderation, SDK RichText, ozone reason tokens, guard rewrites via #/types/bsky). Intermediate checkpoint (hooks skipped): ~114 typecheck errors remain in cross-boundary consumer files, resolved by the type-only codemod next. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import {type QueryClient, useQuery} from '@tanstack/react-query'
|
|
|
|
import {
|
|
aggregateUserInterests,
|
|
createBskyTopicsHeader,
|
|
} from '#/lib/api/feed/utils'
|
|
import {logger} from '#/logger'
|
|
import {getContentLanguages} from '#/state/preferences/languages'
|
|
import {STALE} from '#/state/queries'
|
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
|
import {useAgent} from '#/state/session'
|
|
import {type app} from '#/lexicons'
|
|
|
|
export type QueryProps = {
|
|
category?: string | null
|
|
limit?: number
|
|
}
|
|
|
|
export const getSuggestedUsersForExploreQueryKeyRoot =
|
|
'unspecced-suggested-users-for-explore'
|
|
export const createGetSuggestedUsersForExploreQueryKey = (
|
|
props: QueryProps,
|
|
) => [getSuggestedUsersForExploreQueryKeyRoot, props.category, props.limit]
|
|
|
|
export function useGetSuggestedUsersForExploreQuery(props: QueryProps = {}) {
|
|
const agent = useAgent()
|
|
const {data: preferences} = usePreferencesQuery()
|
|
|
|
return useQuery({
|
|
staleTime: STALE.MINUTES.THREE,
|
|
queryKey: createGetSuggestedUsersForExploreQueryKey(props),
|
|
queryFn: async () => {
|
|
const contentLangs = getContentLanguages().join(',')
|
|
const userInterests = aggregateUserInterests(preferences)
|
|
|
|
const {data} = await agent.app.bsky.unspecced.getSuggestedUsersForExplore(
|
|
{
|
|
category: props.category ?? undefined,
|
|
limit: props.limit || 10,
|
|
},
|
|
{
|
|
headers: {
|
|
...createBskyTopicsHeader(userInterests),
|
|
'Accept-Language': contentLangs,
|
|
},
|
|
},
|
|
)
|
|
|
|
if (!data.recIdStr) {
|
|
logger.debug('getSuggestedUsersForExplore response missing recIdStr')
|
|
}
|
|
return {...data, recId: data.recIdStr}
|
|
},
|
|
})
|
|
}
|
|
|
|
export function* findAllProfilesInQueryData(
|
|
queryClient: QueryClient,
|
|
did: string,
|
|
): Generator<app.bsky.actor.defs.ProfileView, void> {
|
|
const responses = queryClient.getQueriesData<{
|
|
actors: app.bsky.actor.defs.ProfileView[]
|
|
}>({
|
|
queryKey: [getSuggestedUsersForExploreQueryKeyRoot],
|
|
})
|
|
for (const [_key, response] of responses) {
|
|
if (!response) {
|
|
continue
|
|
}
|
|
|
|
for (const actor of response.actors) {
|
|
if (actor.did === did) {
|
|
yield actor
|
|
}
|
|
}
|
|
}
|
|
}
|