migrate service config and composer thread reads to the appview client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 14:57:26 +03:00
parent b3aa00a4d7
commit 935935518a
2 changed files with 29 additions and 22 deletions
+5 -4
View File
@@ -1,7 +1,8 @@
import {useQuery} from '@tanstack/react-query' import {useQuery} from '@tanstack/react-query'
import {STALE} from '#/state/queries' import {STALE} from '#/state/queries'
import {useAgent} from '#/state/session' import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
type ServiceConfig = { type ServiceConfig = {
checkEmailConfirmed: boolean checkEmailConfirmed: boolean
@@ -13,17 +14,17 @@ type ServiceConfig = {
} }
export function useServiceConfigQuery() { export function useServiceConfigQuery() {
const agent = useAgent() const client = useAppviewClient()
return useQuery<ServiceConfig>({ return useQuery<ServiceConfig>({
refetchOnWindowFocus: true, refetchOnWindowFocus: true,
staleTime: STALE.MINUTES.FIVE, staleTime: STALE.MINUTES.FIVE,
queryKey: ['service-config'], queryKey: ['service-config'],
queryFn: async () => { queryFn: async () => {
try { try {
const {data} = await agent.api.app.bsky.unspecced.getConfig() const data = await client.call(app.bsky.unspecced.getConfig)
return { return {
checkEmailConfirmed: Boolean(data.checkEmailConfirmed), 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), topicsEnabled: Boolean(data.topicsEnabled),
liveNow: data.liveNow ?? [], liveNow: data.liveNow ?? [],
} }
+21 -15
View File
@@ -47,12 +47,11 @@ import {type ImagePickerAsset} from 'expo-image-picker'
import { import {
AppBskyDraftCreateDraft, AppBskyDraftCreateDraft,
AppBskyUnspeccedDefs, AppBskyUnspeccedDefs,
type AppBskyUnspeccedGetPostThreadV2,
type AtpAgent,
AtUri, AtUri,
ChatBskyGroupDefs, ChatBskyGroupDefs,
type RichText, type RichText,
} from '@atproto/api' } from '@atproto/api'
import {type Client} from '@atproto/lex'
import {plural} from '@lingui/core/macro' import {plural} from '@lingui/core/macro'
import {Trans, useLingui} from '@lingui/react/macro' import {Trans, useLingui} from '@lingui/react/macro'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'
@@ -96,7 +95,7 @@ import {
import {usePreferencesQuery} from '#/state/queries/preferences' import {usePreferencesQuery} from '#/state/queries/preferences'
import {useProfileQuery} from '#/state/queries/profile' import {useProfileQuery} from '#/state/queries/profile'
import {resolveLinkQueryOptions} from '#/state/queries/resolve-link' 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 {useComposerControls} from '#/state/shell/composer'
import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer' import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer'
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
@@ -144,6 +143,7 @@ import {
IS_WEB_SAFARI, IS_WEB_SAFARI,
} from '#/env' } from '#/env'
import {type Gif} from '#/features/gifPicker/types' import {type Gif} from '#/features/gifPicker/types'
import {app} from '#/lexicons'
import {BottomSheetPortalProvider} from '../../../../modules/bottom-sheet' import {BottomSheetPortalProvider} from '../../../../modules/bottom-sheet'
import { import {
draftToComposerPosts, draftToComposerPosts,
@@ -275,6 +275,7 @@ export const ComposePost = ({
? VIDEO_10_MINUTE_MAX_DURATION_MS ? VIDEO_10_MINUTE_MAX_DURATION_MS
: VIDEO_MAX_DURATION_MS : VIDEO_MAX_DURATION_MS
const agent = useAgent() const agent = useAgent()
const client = useAppviewClient()
const queryClient = useQueryClient() const queryClient = useQueryClient()
const currentDid = currentAccount!.did const currentDid = currentAccount!.did
const {closeComposer} = useComposerControls() const {closeComposer} = useComposerControls()
@@ -1105,23 +1106,27 @@ export const ComposePost = ({
5, 5,
_e => true, _e => true,
async () => { async () => {
const res = await agent.app.bsky.unspecced.getPostThreadV2({ const res = await client.call(
anchor: postUri!, app.bsky.unspecced.getPostThreadV2,
{
anchor:
postUri! as app.bsky.unspecced.getPostThreadV2.$Params['anchor'],
above: false, above: false,
below: filteredThread.posts.length - 1, below: filteredThread.posts.length - 1,
branchingFactor: 1, branchingFactor: 1,
}) },
if (res.data.thread.length !== filteredThread.posts.length) { )
if (res.thread.length !== filteredThread.posts.length) {
throw new Error(`composer: app view is not ready`) throw new Error(`composer: app view is not ready`)
} }
if ( if (
!res.data.thread.every(p => !res.thread.every(p =>
AppBskyUnspeccedDefs.isThreadItemPost(p.value), AppBskyUnspeccedDefs.isThreadItemPost(p.value),
) )
) { ) {
throw new Error(`composer: app view returned non-post items`) throw new Error(`composer: app view returned non-post items`)
} }
return res.data.thread return res.thread
}, },
1e3, 1e3,
) )
@@ -1224,8 +1229,8 @@ export const ComposePost = ({
setLangPrefs.savePostLanguageToHistory() setLangPrefs.savePostLanguageToHistory()
if (initQuote) { if (initQuote) {
// We want to wait for the quote count to update before we call `onPost`, which will refetch data // We want to wait for the quote count to update before we call `onPost`, which will refetch data
void whenAppViewReady(agent, initQuote.uri, res => { void whenAppViewReady(client, initQuote.uri, res => {
const anchor = res.data.thread.at(0) const anchor = res.thread.at(0)
if ( if (
AppBskyUnspeccedDefs.isThreadItemPost(anchor?.value) && AppBskyUnspeccedDefs.isThreadItemPost(anchor?.value) &&
anchor.value.post.quoteCount !== initQuote.quoteCount anchor.value.post.quoteCount !== initQuote.quoteCount
@@ -1272,6 +1277,7 @@ export const ComposePost = ({
l, l,
ax, ax,
agent, agent,
client,
canPost, canPost,
isPublishing, isPublishing,
currentLanguages, currentLanguages,
@@ -2486,17 +2492,17 @@ function useKeyboardVerticalOffset() {
} }
async function whenAppViewReady( async function whenAppViewReady(
agent: AtpAgent, client: Client,
uri: string, uri: string,
fn: (res: AppBskyUnspeccedGetPostThreadV2.Response) => boolean, fn: (res: app.bsky.unspecced.getPostThreadV2.$OutputBody) => boolean,
) { ) {
await until( await until(
5, // 5 tries 5, // 5 tries
1e3, // 1s delay between tries 1e3, // 1s delay between tries
fn, fn,
() => () =>
agent.app.bsky.unspecced.getPostThreadV2({ client.call(app.bsky.unspecced.getPostThreadV2, {
anchor: uri, anchor: uri as app.bsky.unspecced.getPostThreadV2.$Params['anchor'],
above: false, above: false,
below: 0, below: 0,
branchingFactor: 0, branchingFactor: 0,