diff --git a/src/state/queries/service-config.ts b/src/state/queries/service-config.ts index 890a49a5cf..e9f8277b46 100644 --- a/src/state/queries/service-config.ts +++ b/src/state/queries/service-config.ts @@ -1,7 +1,8 @@ import {useQuery} from '@tanstack/react-query' import {STALE} from '#/state/queries' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' type ServiceConfig = { checkEmailConfirmed: boolean @@ -13,17 +14,17 @@ type ServiceConfig = { } export function useServiceConfigQuery() { - const agent = useAgent() + const client = useAppviewClient() return useQuery({ refetchOnWindowFocus: true, staleTime: STALE.MINUTES.FIVE, queryKey: ['service-config'], queryFn: async () => { try { - const {data} = await agent.api.app.bsky.unspecced.getConfig() + const data = await client.call(app.bsky.unspecced.getConfig) return { checkEmailConfirmed: Boolean(data.checkEmailConfirmed), - // @ts-expect-error not included in types atm + // @ts-expect-error not included in the lexicon atm topicsEnabled: Boolean(data.topicsEnabled), liveNow: data.liveNow ?? [], } diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index f9129c56e9..641f651788 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -47,12 +47,11 @@ import {type ImagePickerAsset} from 'expo-image-picker' import { AppBskyDraftCreateDraft, AppBskyUnspeccedDefs, - type AppBskyUnspeccedGetPostThreadV2, - type AtpAgent, AtUri, ChatBskyGroupDefs, type RichText, } from '@atproto/api' +import {type Client} from '@atproto/lex' import {plural} from '@lingui/core/macro' import {Trans, useLingui} from '@lingui/react/macro' import {useNavigation} from '@react-navigation/native' @@ -96,7 +95,7 @@ import { import {usePreferencesQuery} from '#/state/queries/preferences' import {useProfileQuery} from '#/state/queries/profile' import {resolveLinkQueryOptions} from '#/state/queries/resolve-link' -import {useAgent, useSession} from '#/state/session' +import {useAgent, useAppviewClient, useSession} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer' import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' @@ -144,6 +143,7 @@ import { IS_WEB_SAFARI, } from '#/env' import {type Gif} from '#/features/gifPicker/types' +import {app} from '#/lexicons' import {BottomSheetPortalProvider} from '../../../../modules/bottom-sheet' import { draftToComposerPosts, @@ -275,6 +275,7 @@ export const ComposePost = ({ ? VIDEO_10_MINUTE_MAX_DURATION_MS : VIDEO_MAX_DURATION_MS const agent = useAgent() + const client = useAppviewClient() const queryClient = useQueryClient() const currentDid = currentAccount!.did const {closeComposer} = useComposerControls() @@ -1105,23 +1106,27 @@ export const ComposePost = ({ 5, _e => true, async () => { - const res = await agent.app.bsky.unspecced.getPostThreadV2({ - anchor: postUri!, - above: false, - below: filteredThread.posts.length - 1, - branchingFactor: 1, - }) - if (res.data.thread.length !== filteredThread.posts.length) { + const res = await client.call( + app.bsky.unspecced.getPostThreadV2, + { + anchor: + postUri! as app.bsky.unspecced.getPostThreadV2.$Params['anchor'], + above: false, + below: filteredThread.posts.length - 1, + branchingFactor: 1, + }, + ) + if (res.thread.length !== filteredThread.posts.length) { throw new Error(`composer: app view is not ready`) } if ( - !res.data.thread.every(p => + !res.thread.every(p => AppBskyUnspeccedDefs.isThreadItemPost(p.value), ) ) { throw new Error(`composer: app view returned non-post items`) } - return res.data.thread + return res.thread }, 1e3, ) @@ -1224,8 +1229,8 @@ export const ComposePost = ({ setLangPrefs.savePostLanguageToHistory() if (initQuote) { // We want to wait for the quote count to update before we call `onPost`, which will refetch data - void whenAppViewReady(agent, initQuote.uri, res => { - const anchor = res.data.thread.at(0) + void whenAppViewReady(client, initQuote.uri, res => { + const anchor = res.thread.at(0) if ( AppBskyUnspeccedDefs.isThreadItemPost(anchor?.value) && anchor.value.post.quoteCount !== initQuote.quoteCount @@ -1272,6 +1277,7 @@ export const ComposePost = ({ l, ax, agent, + client, canPost, isPublishing, currentLanguages, @@ -2486,17 +2492,17 @@ function useKeyboardVerticalOffset() { } async function whenAppViewReady( - agent: AtpAgent, + client: Client, uri: string, - fn: (res: AppBskyUnspeccedGetPostThreadV2.Response) => boolean, + fn: (res: app.bsky.unspecced.getPostThreadV2.$OutputBody) => boolean, ) { await until( 5, // 5 tries 1e3, // 1s delay between tries fn, () => - agent.app.bsky.unspecced.getPostThreadV2({ - anchor: uri, + client.call(app.bsky.unspecced.getPostThreadV2, { + anchor: uri as app.bsky.unspecced.getPostThreadV2.$Params['anchor'], above: false, below: 0, branchingFactor: 0,