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>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import {type AtUriString} from '@atproto/syntax'
|
|
import {
|
|
type InfiniteData,
|
|
type QueryClient,
|
|
type QueryKey,
|
|
useInfiniteQuery,
|
|
} from '@tanstack/react-query'
|
|
|
|
import {useAppviewClient} from '#/state/session'
|
|
import {app} from '#/lexicons'
|
|
|
|
const PAGE_SIZE = 30
|
|
type RQPageParam = string | undefined
|
|
|
|
// TODO refactor invalidate on mutate?
|
|
const RQKEY_ROOT = 'post-reposted-by'
|
|
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
|
|
|
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
|
const client = useAppviewClient()
|
|
return useInfiniteQuery<
|
|
app.bsky.feed.getRepostedBy.$OutputBody,
|
|
Error,
|
|
InfiniteData<app.bsky.feed.getRepostedBy.$OutputBody>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(resolvedUri || ''),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
return await client.call(app.bsky.feed.getRepostedBy, {
|
|
uri: (resolvedUri || '') as AtUriString,
|
|
limit: PAGE_SIZE,
|
|
cursor: pageParam,
|
|
})
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
enabled: !!resolvedUri,
|
|
})
|
|
}
|
|
|
|
export function* findAllProfilesInQueryData(
|
|
queryClient: QueryClient,
|
|
did: string,
|
|
): Generator<app.bsky.actor.defs.ProfileView, void> {
|
|
const queryDatas = queryClient.getQueriesData<
|
|
InfiniteData<app.bsky.feed.getRepostedBy.$OutputBody>
|
|
>({
|
|
queryKey: [RQKEY_ROOT],
|
|
})
|
|
for (const [_queryKey, queryData] of queryDatas) {
|
|
if (!queryData?.pages) {
|
|
continue
|
|
}
|
|
for (const page of queryData?.pages) {
|
|
for (const repostedBy of page.repostedBy) {
|
|
if (repostedBy.did === did) {
|
|
yield repostedBy
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|