e7d349bc30
Task 8: codemod repointed 150 namespace-type files to #/lexicons (AppBskyFeedDefs.PostView -> app.bsky.feed.defs.PostView, .Record -> .Main) plus ~105 hand-fixed consumers (composer/video state, DebugMod, Profile, onboarding, dialogs). DM_SERVICE_HEADERS deleted; last chat call sites on the chat client. RichText.tsx flipped to SDK-only. Remaining @atproto/api importers: the three session bridge files, the deliberate dual-world matcher in lib/xrpc-error.ts, and test fixtures. toLex boundary casts are TODO(phase4)-tagged for bridge removal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
85 lines
2.5 KiB
TypeScript
85 lines
2.5 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'
|
|
import {toLex} from '#/types/bsky'
|
|
|
|
export type QueryProps = {
|
|
limit?: number
|
|
}
|
|
|
|
export const getSuggestedUsersForDiscoverQueryKeyRoot =
|
|
'unspecced-suggested-users-for-explore'
|
|
export const createGetSuggestedUsersForDiscoverQueryKey = (props: {
|
|
limit?: number
|
|
}) => [getSuggestedUsersForDiscoverQueryKeyRoot, props.limit]
|
|
|
|
export function useGetSuggestedUsersForDiscoverQuery(props: QueryProps = {}) {
|
|
const agent = useAgent()
|
|
const {data: preferences} = usePreferencesQuery()
|
|
|
|
return useQuery({
|
|
staleTime: STALE.MINUTES.THREE,
|
|
queryKey: createGetSuggestedUsersForDiscoverQueryKey({limit: props.limit}),
|
|
queryFn: async () => {
|
|
const contentLangs = getContentLanguages().join(',')
|
|
const userInterests = aggregateUserInterests(preferences)
|
|
|
|
const {data} =
|
|
await agent.app.bsky.unspecced.getSuggestedUsersForDiscover(
|
|
{
|
|
limit: props.limit || 10,
|
|
},
|
|
{
|
|
headers: {
|
|
...createBskyTopicsHeader(userInterests),
|
|
'Accept-Language': contentLangs,
|
|
},
|
|
},
|
|
)
|
|
if (!data.recIdStr) {
|
|
logger.debug('getSuggestedUsersForDiscover response missing recIdStr')
|
|
}
|
|
/*
|
|
* TODO(phase4): drop toLex once getSuggestedUsersForDiscover migrates off
|
|
* the bridge agent (this unspecced endpoint is intentionally left on the
|
|
* bridge in Phase 3, so it returns old `@atproto/api` view types).
|
|
*/
|
|
return toLex<{
|
|
actors: app.bsky.actor.defs.ProfileView[]
|
|
recId: string | undefined
|
|
}>({...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: [getSuggestedUsersForDiscoverQueryKeyRoot],
|
|
})
|
|
for (const [_key, response] of responses) {
|
|
if (!response) {
|
|
continue
|
|
}
|
|
|
|
for (const actor of response.actors) {
|
|
if (actor.did === did) {
|
|
yield actor
|
|
}
|
|
}
|
|
}
|
|
}
|