Files
bsky-social-app/src/state/queries/messages/lock-conversation.ts
T
Samuel Newman 300a50b69a 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>
2026-07-30 18:12:10 +03:00

68 lines
1.7 KiB
TypeScript

import {useMutation, useQueryClient} from '@tanstack/react-query'
import {useChatClient} from '#/state/session'
import {chat} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {
rollbackConvoOptimistic,
updateConvoOptimistic,
} from './utils/convo-cache'
export function useLockConvo(
convoId: string | undefined,
{
onSuccess,
onError,
}: {
onSuccess?: (
data: chat.bsky.convo.lockConvo.$OutputBody,
variables: {lock: boolean; silent?: boolean},
) => void
onError?: (
error: Error,
variables: {lock: boolean; silent?: boolean},
) => void
},
) {
const queryClient = useQueryClient()
const chatClient = useChatClient()
return useMutation({
mutationFn: async ({lock}: {lock: boolean; silent?: boolean}) => {
if (!convoId) throw new Error('No convoId provided')
if (lock) {
const data = await chatClient.call(chat.bsky.convo.lockConvo, {convoId})
return data
} else {
const data = await chatClient.call(chat.bsky.convo.unlockConvo, {
convoId,
})
return data
}
},
onMutate: ({lock}) => {
if (!convoId) return
return updateConvoOptimistic(queryClient, convoId, prev => {
if (!bsky.isType(chat.bsky.convo.defs.groupConvo, prev.kind))
return undefined
return {
...prev,
kind: {
...prev.kind,
lockStatus: lock ? 'locked' : 'unlocked',
},
}
})
},
onSuccess: (data, variables) => {
onSuccess?.(data, variables)
},
onError: (e, variables, context) => {
if (convoId && context) {
rollbackConvoOptimistic(queryClient, convoId, context)
}
onError?.(e, variables)
},
})
}