From 0912119c7790f761f0f4e59574dcd4a8cfdd4c65 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 13 Aug 2026 22:26:15 +0300 Subject: [PATCH] [SDK] Migrate profile and graph read queries to the appview client (#11356) Co-authored-by: Claude Fable 5 --- src/state/queries/actor-starter-packs.ts | 20 +++++----- src/state/queries/known-followers.ts | 23 ++++++----- src/state/queries/list-members.ts | 23 ++++++----- src/state/queries/lists-with-membership.ts | 35 +++++++++-------- src/state/queries/my-blocked-accounts.ts | 16 ++++---- src/state/queries/my-lists.ts | 38 ++++++++++--------- src/state/queries/my-muted-accounts.ts | 16 ++++---- src/state/queries/pinned-post.ts | 10 +++-- src/state/queries/profile-feedgens.ts | 23 ++++++----- src/state/queries/profile-followers.ts | 32 +++++++++------- src/state/queries/profile-follows.ts | 29 ++++++++------ src/state/queries/profile-lists.ts | 18 ++++----- src/state/queries/suggested-follows.ts | 29 +++++++------- .../useUpdateProfileVerificationCache.ts | 16 +++++--- 14 files changed, 180 insertions(+), 148 deletions(-) diff --git a/src/state/queries/actor-starter-packs.ts b/src/state/queries/actor-starter-packs.ts index 97cc3b5e05..cef91c6bd6 100644 --- a/src/state/queries/actor-starter-packs.ts +++ b/src/state/queries/actor-starter-packs.ts @@ -1,6 +1,8 @@ +import {type DidString} from '@atproto/syntax' import {type QueryClient, useInfiniteQuery} from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' export const RQKEY_ROOT = 'actor-starter-packs' export const RQKEY_WITH_MEMBERSHIP_ROOT = 'actor-starter-packs-with-membership' @@ -17,17 +19,17 @@ export function useActorStarterPacksQuery({ did?: string enabled?: boolean }) { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery({ queryKey: RQKEY(did), queryFn: async ({pageParam}: {pageParam?: string}) => { - const res = await agent.app.bsky.graph.getActorStarterPacks({ - actor: did!, + return await client.call(app.bsky.graph.getActorStarterPacks, { + // the enabled flag prevents this from running until did is set + actor: did! as DidString, limit: 10, cursor: pageParam, }) - return res.data }, enabled: Boolean(did) && enabled, initialPageParam: undefined, @@ -42,17 +44,17 @@ export function useActorStarterPacksWithMembershipsQuery({ did?: string enabled?: boolean }) { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery({ queryKey: RQKEY_WITH_MEMBERSHIP(did), queryFn: async ({pageParam}: {pageParam?: string}) => { - const res = await agent.app.bsky.graph.getStarterPacksWithMembership({ - actor: did!, + return await client.call(app.bsky.graph.getStarterPacksWithMembership, { + // the enabled flag prevents this from running until did is set + actor: did! as DidString, limit: 10, cursor: pageParam, }) - return res.data }, enabled: Boolean(did) && enabled, initialPageParam: undefined, diff --git a/src/state/queries/known-followers.ts b/src/state/queries/known-followers.ts index 05bbd5e67c..3106456f9d 100644 --- a/src/state/queries/known-followers.ts +++ b/src/state/queries/known-followers.ts @@ -1,7 +1,5 @@ -import { - type AppBskyActorDefs, - type AppBskyGraphGetKnownFollowers, -} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -9,7 +7,8 @@ import { useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' const PAGE_SIZE = 50 type RQPageParam = string | undefined @@ -18,22 +17,22 @@ const RQKEY_ROOT = 'profile-known-followers' export const RQKEY = (did: string) => [RQKEY_ROOT, did] export function useProfileKnownFollowersQuery(did: string | undefined) { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetKnownFollowers.OutputSchema, + app.bsky.graph.getKnownFollowers.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(did || ''), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getKnownFollowers({ - actor: did!, + return await client.call(app.bsky.graph.getKnownFollowers, { + // the enabled flag prevents this from running until did is set + actor: did! as DidString, limit: PAGE_SIZE, cursor: pageParam, }) - return res.data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -46,7 +45,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/list-members.ts b/src/state/queries/list-members.ts index c43c7bb983..bde6666dc6 100644 --- a/src/state/queries/list-members.ts +++ b/src/state/queries/list-members.ts @@ -1,9 +1,9 @@ import { type AppBskyActorDefs, type AppBskyGraphDefs, - type AppBskyGraphGetList, type AtpAgent, } from '@atproto/api' +import {type AtUriString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -13,7 +13,8 @@ import { } from '@tanstack/react-query' import {STALE} from '#/state/queries' -import {useAgent} from '#/state/session' +import {useAgent, useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' const PAGE_SIZE = 30 type RQPageParam = string | undefined @@ -24,23 +25,23 @@ export const RQKEY = (uri: string) => [RQKEY_ROOT, uri] export const RQKEY_ALL = (uri: string) => [RQKEY_ROOT_ALL, uri] export function useListMembersQuery(uri?: string, limit: number = PAGE_SIZE) { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetList.OutputSchema, + app.bsky.graph.getList.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ staleTime: STALE.MINUTES.ONE, queryKey: RQKEY(uri ?? ''), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getList({ - list: uri!, // the enabled flag will prevent this from running until uri is set + return await client.call(app.bsky.graph.getList, { + // the enabled flag will prevent this from running until uri is set + list: uri! as AtUriString, limit, cursor: pageParam, }) - return res.data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -60,6 +61,10 @@ export function useAllListMembersQuery(uri?: string) { }) } +/* + * Still on the legacy agent: four call sites outside this cluster pass their + * own `AtpAgent`, so the parameter type is migrated with those consumers. + */ export async function getAllListMembers(agent: AtpAgent, uri: string) { let hasMore = true let cursor: string | undefined @@ -95,7 +100,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/lists-with-membership.ts b/src/state/queries/lists-with-membership.ts index 3147b8845f..1bd09704b9 100644 --- a/src/state/queries/lists-with-membership.ts +++ b/src/state/queries/lists-with-membership.ts @@ -1,7 +1,5 @@ -import { - type AppBskyActorDefs, - type AppBskyGraphGetListsWithMembership, -} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' +import {type AtIdentifierString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -10,10 +8,11 @@ import { } from '@tanstack/react-query' import {createQueryKey} from '#/state/queries/util' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' export type ListWithMembership = - AppBskyGraphGetListsWithMembership.ListWithMembership + app.bsky.graph.getListsWithMembership.ListWithMembership const listsWithMembershipQueryKeyRoot = 'lists-with-membership' export const createListsWithMembershipQueryKey = (args: {actor: string}) => @@ -26,23 +25,23 @@ export function useListsWithMembershipQuery({ actor: string | undefined enabled?: boolean }) { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetListsWithMembership.OutputSchema, + app.bsky.graph.getListsWithMembership.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, string | undefined >({ queryKey: createListsWithMembershipQueryKey({actor: actor ?? ''}), queryFn: async ({pageParam}: {pageParam?: string}) => { - const res = await agent.app.bsky.graph.getListsWithMembership({ - actor: actor!, // the enabled flag prevents this from running until actor is set + return await client.call(app.bsky.graph.getListsWithMembership, { + // the enabled flag prevents this from running until actor is set + actor: actor! as AtIdentifierString, limit: 50, cursor: pageParam, }) - return res.data }, enabled: Boolean(actor) && enabled, initialPageParam: undefined, @@ -64,7 +63,7 @@ export function updateListMembershipOptimistically({ subject: AppBskyActorDefs.ProfileView }) { queryClient.setQueryData< - InfiniteData + InfiniteData >(createListsWithMembershipQueryKey({actor}), old => { if (!old) return old @@ -74,12 +73,18 @@ export function updateListMembershipOptimistically({ ...page, listsWithMembership: page.listsWithMembership.map(lwm => { if (lwm.list.uri === listUri) { + /* + * Callers hand over a plain at-uri and an old-world ProfileView, + * whose `uri`/`did` are unbranded strings. They are runtime + * identical to the generated branded forms, so the synthesised + * listItem is asserted rather than re-validated. + */ return { ...lwm, listItem: { uri: membershipUri, subject, - }, + } as app.bsky.graph.defs.ListItemView, } } return lwm @@ -99,7 +104,7 @@ export function removeListMembershipOptimistically({ listUri: string }) { queryClient.setQueryData< - InfiniteData + InfiniteData >(createListsWithMembershipQueryKey({actor}), old => { if (!old) return old diff --git a/src/state/queries/my-blocked-accounts.ts b/src/state/queries/my-blocked-accounts.ts index a2e29136f5..2cbe1dea29 100644 --- a/src/state/queries/my-blocked-accounts.ts +++ b/src/state/queries/my-blocked-accounts.ts @@ -1,4 +1,4 @@ -import {type AppBskyActorDefs, type AppBskyGraphGetBlocks} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' import { type InfiniteData, type QueryClient, @@ -6,28 +6,28 @@ import { useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' const RQKEY_ROOT = 'my-blocked-accounts' export const RQKEY = () => [RQKEY_ROOT] type RQPageParam = string | undefined export function useMyBlockedAccountsQuery() { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetBlocks.OutputSchema, + app.bsky.graph.getBlocks.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getBlocks({ + return await client.call(app.bsky.graph.getBlocks, { limit: 30, cursor: pageParam, }) - return res.data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -39,7 +39,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/my-lists.ts b/src/state/queries/my-lists.ts index aeb9cf4568..d4538104dd 100644 --- a/src/state/queries/my-lists.ts +++ b/src/state/queries/my-lists.ts @@ -1,9 +1,11 @@ import {type AppBskyGraphDefs} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import {type QueryClient, useQuery} from '@tanstack/react-query' import {accumulate} from '#/lib/async/accumulate' import {STALE} from '#/state/queries' -import {useAgent, useSession} from '#/state/session' +import {useAppviewClient, useSession} from '#/state/session' +import {app} from '#/lexicons' export type MyListsFilter = | 'all' @@ -16,7 +18,7 @@ export const RQKEY = (filter: MyListsFilter) => [RQKEY_ROOT, filter] export function useMyListsQuery(filter: MyListsFilter) { const {currentAccount} = useSession() - const agent = useAgent() + const client = useAppviewClient() return useQuery({ staleTime: STALE.MINUTES.ONE, queryKey: RQKEY(filter), @@ -24,42 +26,42 @@ export function useMyListsQuery(filter: MyListsFilter) { let lists: AppBskyGraphDefs.ListView[] = [] const promises = [ accumulate(cursor => - agent.app.bsky.graph - .getLists({ - actor: currentAccount!.did, + client + .call(app.bsky.graph.getLists, { + actor: currentAccount!.did as DidString, cursor, limit: 50, }) - .then(res => ({ - cursor: res.data.cursor, - items: res.data.lists, + .then(data => ({ + cursor: data.cursor, + items: data.lists, })), ), ] if (filter === 'all-including-subscribed' || filter === 'mod') { promises.push( accumulate(cursor => - agent.app.bsky.graph - .getListMutes({ + client + .call(app.bsky.graph.getListMutes, { cursor, limit: 50, }) - .then(res => ({ - cursor: res.data.cursor, - items: res.data.lists, + .then(data => ({ + cursor: data.cursor, + items: data.lists, })), ), ) promises.push( accumulate(cursor => - agent.app.bsky.graph - .getListBlocks({ + client + .call(app.bsky.graph.getListBlocks, { cursor, limit: 50, }) - .then(res => ({ - cursor: res.data.cursor, - items: res.data.lists, + .then(data => ({ + cursor: data.cursor, + items: data.lists, })), ), ) diff --git a/src/state/queries/my-muted-accounts.ts b/src/state/queries/my-muted-accounts.ts index bf36b90296..cd1c6bc6ba 100644 --- a/src/state/queries/my-muted-accounts.ts +++ b/src/state/queries/my-muted-accounts.ts @@ -1,4 +1,4 @@ -import {type AppBskyActorDefs, type AppBskyGraphGetMutes} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' import { type InfiniteData, type QueryClient, @@ -6,28 +6,28 @@ import { useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' const RQKEY_ROOT = 'my-muted-accounts' export const RQKEY = () => [RQKEY_ROOT] type RQPageParam = string | undefined export function useMyMutedAccountsQuery() { - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetMutes.OutputSchema, + app.bsky.graph.getMutes.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getMutes({ + return await client.call(app.bsky.graph.getMutes, { limit: 30, cursor: pageParam, }) - return res.data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -39,7 +39,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/pinned-post.ts b/src/state/queries/pinned-post.ts index 09a0b4c9b9..d132127e68 100644 --- a/src/state/queries/pinned-post.ts +++ b/src/state/queries/pinned-post.ts @@ -1,3 +1,4 @@ +import {type DidString} from '@atproto/syntax' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {useMutation, useQueryClient} from '@tanstack/react-query' @@ -5,14 +6,15 @@ import {useMutation, useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed' import * as Toast from '#/components/Toast' +import {app} from '#/lexicons' import {updatePostShadow} from '../cache/post-shadow' -import {useAgent, useSession} from '../session' +import {useAppviewClient, useSession} from '../session' import {useProfileUpdateMutation} from './profile' export function usePinnedPostMutation() { const {_} = useLingui() const {currentAccount} = useSession() - const agent = useAgent() + const client = useAppviewClient() const queryClient = useQueryClient() const {mutateAsync: profileUpdateMutate} = useProfileUpdateMutation() @@ -33,8 +35,8 @@ export function usePinnedPostMutation() { // get the currently pinned post so we can optimistically remove the pin from it if (!currentAccount) throw new Error('Not signed in') - const {data: profile} = await agent.getProfile({ - actor: currentAccount.did, + const profile = await client.call(app.bsky.actor.getProfile, { + actor: currentAccount.did as DidString, }) prevPinnedPost = profile.pinnedPost?.uri if (prevPinnedPost && prevPinnedPost !== postUri) { diff --git a/src/state/queries/profile-feedgens.ts b/src/state/queries/profile-feedgens.ts index 56e7c70182..7bdcd62b64 100644 --- a/src/state/queries/profile-feedgens.ts +++ b/src/state/queries/profile-feedgens.ts @@ -1,14 +1,13 @@ -import { - type AppBskyFeedGetActorFeeds, - moderateFeedGenerator, -} from '@atproto/api' +import {moderateFeedGenerator} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryKey, useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' import {useModerationOpts} from '../preferences/moderation-opts' const PAGE_SIZE = 50 @@ -24,25 +23,25 @@ export function useProfileFeedgensQuery( ) { const moderationOpts = useModerationOpts() const enabled = opts?.enabled !== false && Boolean(moderationOpts) - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyFeedGetActorFeeds.OutputSchema, + app.bsky.feed.getActorFeeds.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(did), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.feed.getActorFeeds({ - actor: did, + const data = await client.call(app.bsky.feed.getActorFeeds, { + actor: did as DidString, limit: PAGE_SIZE, cursor: pageParam, }) - res.data.feeds.sort((a, b) => { + data.feeds.sort((a, b) => { return (b.likeCount || 0) - (a.likeCount || 0) }) - return res.data + return data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, diff --git a/src/state/queries/profile-followers.ts b/src/state/queries/profile-followers.ts index 62968af2d8..5022ae9576 100644 --- a/src/state/queries/profile-followers.ts +++ b/src/state/queries/profile-followers.ts @@ -1,7 +1,5 @@ -import { - type AppBskyActorDefs, - type AppBskyGraphGetFollowers, -} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -9,8 +7,9 @@ import { useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' import {useAnalytics} from '#/analytics' +import {app} from '#/lexicons' const DEFAULT_SORT = 'latest' const PAGE_SIZE = 30 @@ -33,26 +32,31 @@ export function useProfileFollowersQuery( ) { const ax = useAnalytics() const isSortEnabled = ax.features.enabled(ax.features.FollowSortEnable) - const agent = useAgent() + const client = useAppviewClient() const sortParam = isSortEnabled ? sort || DEFAULT_SORT : undefined return useInfiniteQuery< - AppBskyGraphGetFollowers.OutputSchema, + app.bsky.graph.getFollowers.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(did || '', sortParam), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getFollowers({ - actor: did || '', + /* + * The vendored lexicon does not declare `sort`, so it is spread in only + * when set and the whole params object is asserted. lex forwards + * undeclared params verbatim but rejects an undeclared key whose value + * is `undefined`, hence the conditional spread. + */ + return await client.call(app.bsky.graph.getFollowers, { + actor: (did || '') as DidString, limit: PAGE_SIZE, cursor: pageParam, - sort: sortParam, - }) - return res.data + ...(sortParam ? {sort: sortParam} : {}), + } as app.bsky.graph.getFollowers.$Params) }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -65,7 +69,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/profile-follows.ts b/src/state/queries/profile-follows.ts index 1c4d5dc69c..1cd857af16 100644 --- a/src/state/queries/profile-follows.ts +++ b/src/state/queries/profile-follows.ts @@ -1,4 +1,5 @@ -import {type AppBskyActorDefs, type AppBskyGraphGetFollows} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -7,8 +8,9 @@ import { } from '@tanstack/react-query' import {STALE} from '#/state/queries' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' import {useAnalytics} from '#/analytics' +import {app} from '#/lexicons' const DEFAULT_SORT = 'latest' const PAGE_SIZE = 30 @@ -34,27 +36,32 @@ export function useProfileFollowsQuery( ) { const ax = useAnalytics() const isSortEnabled = ax.features.enabled(ax.features.FollowSortEnable) - const agent = useAgent() + const client = useAppviewClient() const sortParam = isSortEnabled ? sort || DEFAULT_SORT : undefined return useInfiniteQuery< - AppBskyGraphGetFollows.OutputSchema, + app.bsky.graph.getFollows.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ staleTime: STALE.MINUTES.ONE, queryKey: RQKEY(did || '', sortParam), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getFollows({ - actor: did || '', + /* + * The vendored lexicon does not declare `sort`, so it is spread in only + * when set and the whole params object is asserted. lex forwards + * undeclared params verbatim but rejects an undeclared key whose value + * is `undefined`, hence the conditional spread. + */ + return await client.call(app.bsky.graph.getFollows, { + actor: (did || '') as DidString, limit: limit || PAGE_SIZE, cursor: pageParam, - sort: sortParam, - }) - return res.data + ...(sortParam ? {sort: sortParam} : {}), + } as app.bsky.graph.getFollows.$Params) }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -67,7 +74,7 @@ export function* findAllProfilesInQueryData( did: string, ): Generator { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [RQKEY_ROOT], }) diff --git a/src/state/queries/profile-lists.ts b/src/state/queries/profile-lists.ts index 965da72e51..0237876513 100644 --- a/src/state/queries/profile-lists.ts +++ b/src/state/queries/profile-lists.ts @@ -1,11 +1,13 @@ -import {type AppBskyGraphGetLists, moderateUserList} from '@atproto/api' +import {moderateUserList} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryKey, useInfiniteQuery, } from '@tanstack/react-query' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' import {useModerationOpts} from '../preferences/moderation-opts' const PAGE_SIZE = 30 @@ -17,23 +19,21 @@ export const RQKEY = (did: string) => [RQKEY_ROOT, did] export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) { const moderationOpts = useModerationOpts() const enabled = opts?.enabled !== false && Boolean(moderationOpts) - const agent = useAgent() + const client = useAppviewClient() return useInfiniteQuery< - AppBskyGraphGetLists.OutputSchema, + app.bsky.graph.getLists.$OutputBody, Error, - InfiniteData, + InfiniteData, QueryKey, RQPageParam >({ queryKey: RQKEY(did), async queryFn({pageParam}: {pageParam: RQPageParam}) { - const res = await agent.app.bsky.graph.getLists({ - actor: did, + return await client.call(app.bsky.graph.getLists, { + actor: did as DidString, limit: PAGE_SIZE, cursor: pageParam, }) - - return res.data }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, diff --git a/src/state/queries/suggested-follows.ts b/src/state/queries/suggested-follows.ts index 7197eb2980..12f726baea 100644 --- a/src/state/queries/suggested-follows.ts +++ b/src/state/queries/suggested-follows.ts @@ -1,9 +1,6 @@ import {useCallback, useMemo} from 'react' -import { - type AppBskyActorDefs, - type AppBskyActorGetSuggestions, - type AppBskyGraphGetSuggestedFollowsByActor, -} from '@atproto/api' +import {type AppBskyActorDefs} from '@atproto/api' +import {type DidString} from '@atproto/syntax' import { type InfiniteData, type QueryClient, @@ -12,7 +9,8 @@ import { } from '@tanstack/react-query' import {STALE} from '#/state/queries' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' import type * as bsky from '#/types/bsky' const suggestedFollowsQueryKeyRoot = 'suggested-follows' @@ -32,18 +30,21 @@ export function useSuggestedFollowsByActorQuery({ enabled?: boolean staleTime?: number }) { - const agent = useAgent() + const client = useAppviewClient() return useQuery({ staleTime, queryKey: suggestedFollowsByActorQueryKey(did), queryFn: async () => { - const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({ - actor: did, - }) - const suggestions = res.data.suggestions.filter( + const data = await client.call( + app.bsky.graph.getSuggestedFollowsByActor, + { + actor: did as DidString, + }, + ) + const suggestions = data.suggestions.filter( profile => !profile.viewer?.following, ) - return {suggestions, recId: res.data.recIdStr} + return {suggestions, recId: data.recIdStr} }, enabled, }) @@ -112,7 +113,7 @@ function* findAllProfilesInSuggestedFollowsQueryData( did: string, ) { const queryDatas = queryClient.getQueriesData< - InfiniteData + InfiniteData >({ queryKey: [suggestedFollowsQueryKeyRoot], }) @@ -135,7 +136,7 @@ function* findAllProfilesInSuggestedFollowsByActorQueryData( did: string, ) { const queryDatas = - queryClient.getQueriesData( + queryClient.getQueriesData( { queryKey: [suggestedFollowsByActorQueryKeyRoot], }, diff --git a/src/state/queries/verification/useUpdateProfileVerificationCache.ts b/src/state/queries/verification/useUpdateProfileVerificationCache.ts index f5ccf1458b..08da1244c5 100644 --- a/src/state/queries/verification/useUpdateProfileVerificationCache.ts +++ b/src/state/queries/verification/useUpdateProfileVerificationCache.ts @@ -1,9 +1,11 @@ import {useCallback} from 'react' +import {type DidString} from '@atproto/syntax' import {useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' import {updateProfileShadow} from '#/state/cache/profile-shadow' -import {useAgent} from '#/state/session' +import {useAppviewClient} from '#/state/session' +import {app} from '#/lexicons' import type * as bsky from '#/types/bsky' /** @@ -13,13 +15,17 @@ import type * as bsky from '#/types/bsky' */ export function useUpdateProfileVerificationCache() { const qc = useQueryClient() - const agent = useAgent() + const client = useAppviewClient() return useCallback( async ({profile}: {profile: bsky.profile.AnyProfileView}) => { try { - const {data: updated} = await agent.getProfile({ - actor: profile.did ?? '', + if (!profile.did) { + logger.warn(`useUpdateProfileVerificationCache: no did`, {profile}) + return + } + const updated = await client.call(app.bsky.actor.getProfile, { + actor: profile.did as DidString, }) updateProfileShadow(qc, profile.did, { verification: updated.verification, @@ -30,6 +36,6 @@ export function useUpdateProfileVerificationCache() { }) } }, - [agent, qc], + [client, qc], ) }