migrate runtime call sites to lex clients and sdk actions
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>
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
import {
|
||||
type ChatBskyActorDefs,
|
||||
type ChatBskyConvoDefs,
|
||||
type ChatBskyConvoGetConvo,
|
||||
type ChatBskyConvoGetUnreadCounts,
|
||||
} from '@atproto/api'
|
||||
import {
|
||||
type QueryClient,
|
||||
useMutation,
|
||||
@@ -11,10 +5,10 @@ import {
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {DM_SERVICE_HEADERS} from '#/lib/constants'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useOnMarkAsRead} from '#/state/queries/messages/list-conversations'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useChatClient} from '#/state/session'
|
||||
import {chat} from '#/lexicons'
|
||||
import {
|
||||
RQKEY_PARTIAL as UNREAD_COUNTS_PARTIAL_KEY,
|
||||
UNREAD_ACCEPTED_CAP,
|
||||
@@ -30,15 +24,12 @@ export const RQKEY_ROOT = 'convo'
|
||||
export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId]
|
||||
|
||||
export function useConvoQuery({convoId}: {convoId: string}) {
|
||||
const agent = useAgent()
|
||||
const chatClient = useChatClient()
|
||||
|
||||
return useQuery({
|
||||
queryKey: RQKEY(convoId),
|
||||
queryFn: async () => {
|
||||
const {data} = await agent.chat.bsky.convo.getConvo(
|
||||
{convoId},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
const data = await chatClient.call(chat.bsky.convo.getConvo, {convoId})
|
||||
return data.convo
|
||||
},
|
||||
staleTime: STALE.INFINITY,
|
||||
@@ -47,7 +38,7 @@ export function useConvoQuery({convoId}: {convoId: string}) {
|
||||
|
||||
export function precacheConvoQuery(
|
||||
queryClient: QueryClient,
|
||||
convo: ChatBskyConvoDefs.ConvoView,
|
||||
convo: chat.bsky.convo.defs.ConvoView,
|
||||
) {
|
||||
queryClient.setQueryData(RQKEY(convo.id), convo)
|
||||
}
|
||||
@@ -55,7 +46,7 @@ export function precacheConvoQuery(
|
||||
export function useMarkAsReadMutation() {
|
||||
const optimisticUpdate = useOnMarkAsRead()
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const chatClient = useChatClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
@@ -67,16 +58,10 @@ export function useMarkAsReadMutation() {
|
||||
}) => {
|
||||
if (!convoId) throw new Error('No convoId provided')
|
||||
|
||||
await agent.chat.bsky.convo.updateRead(
|
||||
{
|
||||
convoId,
|
||||
messageId,
|
||||
},
|
||||
{
|
||||
encoding: 'application/json',
|
||||
headers: DM_SERVICE_HEADERS,
|
||||
},
|
||||
)
|
||||
await chatClient.call(chat.bsky.convo.updateRead, {
|
||||
convoId,
|
||||
messageId,
|
||||
})
|
||||
},
|
||||
onMutate({convoId}) {
|
||||
if (!convoId) throw new Error('No convoId provided')
|
||||
@@ -90,7 +75,7 @@ export function useMarkAsReadMutation() {
|
||||
// find the convo so we know which badge counter (if any) to decrement.
|
||||
// keep scanning past a stale unreadCount === 0 cache so another cache
|
||||
// holding the true unread state still drives the decrement
|
||||
let unreadStatus: ChatBskyConvoDefs.ConvoView['status'] | undefined
|
||||
let unreadStatus: chat.bsky.convo.defs.ConvoView['status'] | undefined
|
||||
for (const [, data] of prevListQueries) {
|
||||
if (!data) continue
|
||||
const convo = getConvoFromQueryData(convoId, data)
|
||||
@@ -105,11 +90,13 @@ export function useMarkAsReadMutation() {
|
||||
// the badge count query is a separate server query that the list caches
|
||||
// don't feed, so decrement it here to keep the badge in sync
|
||||
const prevUnreadCountsQueries =
|
||||
queryClient.getQueriesData<ChatBskyConvoGetUnreadCounts.OutputSchema>({
|
||||
queryKey: UNREAD_COUNTS_PARTIAL_KEY,
|
||||
})
|
||||
queryClient.getQueriesData<chat.bsky.convo.getUnreadCounts.$OutputBody>(
|
||||
{
|
||||
queryKey: UNREAD_COUNTS_PARTIAL_KEY,
|
||||
},
|
||||
)
|
||||
if (unreadStatus) {
|
||||
queryClient.setQueriesData<ChatBskyConvoGetUnreadCounts.OutputSchema>(
|
||||
queryClient.setQueriesData<chat.bsky.convo.getUnreadCounts.$OutputBody>(
|
||||
{queryKey: UNREAD_COUNTS_PARTIAL_KEY},
|
||||
old => {
|
||||
if (!old) return old
|
||||
@@ -193,9 +180,9 @@ export function useMarkAsReadMutation() {
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
): Generator<ChatBskyActorDefs.ProfileViewBasic, void> {
|
||||
): Generator<chat.bsky.actor.defs.ProfileViewBasic, void> {
|
||||
const queryDatas = queryClient.getQueriesData<
|
||||
ChatBskyConvoGetConvo.OutputSchema['convo']
|
||||
chat.bsky.convo.getConvo.$OutputBody['convo']
|
||||
>({
|
||||
queryKey: [RQKEY_ROOT],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user