migrate getAllListMembers to the appview client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import {wait} from '#/lib/async/wait'
|
|||||||
import {type NavigationProp} from '#/lib/routes/types'
|
import {type NavigationProp} from '#/lib/routes/types'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {getAllListMembers} from '#/state/queries/list-members'
|
import {getAllListMembers} from '#/state/queries/list-members'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useAppviewClient, useSession} from '#/state/session'
|
||||||
import {atoms as a, platform, useTheme, web} from '#/alf'
|
import {atoms as a, platform, useTheme, web} from '#/alf'
|
||||||
import {Admonition} from '#/components/Admonition'
|
import {Admonition} from '#/components/Admonition'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
@@ -41,6 +41,7 @@ export function CreateListFromStarterPackDialog({
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const appviewClient = useAppviewClient()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
@@ -73,7 +74,10 @@ export function CreateListFromStarterPackDialog({
|
|||||||
const listItems = await wait(
|
const listItems = await wait(
|
||||||
3000,
|
3000,
|
||||||
(async () => {
|
(async () => {
|
||||||
const items = await getAllListMembers(agent, starterPack.list!.uri)
|
const items = await getAllListMembers(
|
||||||
|
appviewClient,
|
||||||
|
starterPack.list!.uri,
|
||||||
|
)
|
||||||
|
|
||||||
if (items.length > 0) {
|
if (items.length > 0) {
|
||||||
const listitemWrites: $Typed<ComAtprotoRepoApplyWrites.Create>[] =
|
const listitemWrites: $Typed<ComAtprotoRepoApplyWrites.Create>[] =
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-p
|
|||||||
import {getAllListMembers} from '#/state/queries/list-members'
|
import {getAllListMembers} from '#/state/queries/list-members'
|
||||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||||
import {RQKEY as profileRQKey} from '#/state/queries/profile'
|
import {RQKEY as profileRQKey} from '#/state/queries/profile'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent, useAppviewClient} from '#/state/session'
|
||||||
import {useOnboardingDispatch} from '#/state/shell'
|
import {useOnboardingDispatch} from '#/state/shell'
|
||||||
import {
|
import {
|
||||||
useActiveStarterPack,
|
useActiveStarterPack,
|
||||||
@@ -58,6 +58,7 @@ export function StepFinished() {
|
|||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const appviewClient = useAppviewClient()
|
||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const activeStarterPack = useActiveStarterPack()
|
const activeStarterPack = useActiveStarterPack()
|
||||||
const setActiveStarterPack = useSetActiveStarterPack()
|
const setActiveStarterPack = useSetActiveStarterPack()
|
||||||
@@ -82,7 +83,10 @@ export function StepFinished() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (starterPack?.list) {
|
if (starterPack?.list) {
|
||||||
listItems = await getAllListMembers(agent, starterPack.list.uri)
|
listItems = await getAllListMembers(
|
||||||
|
appviewClient,
|
||||||
|
starterPack.list.uri,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('Failed to fetch starter pack list items', {
|
logger.error('Failed to fetch starter pack list items', {
|
||||||
@@ -231,6 +235,7 @@ export function StepFinished() {
|
|||||||
ax,
|
ax,
|
||||||
queryClient,
|
queryClient,
|
||||||
agent,
|
agent,
|
||||||
|
appviewClient,
|
||||||
dispatch,
|
dispatch,
|
||||||
onboardDispatch,
|
onboardDispatch,
|
||||||
activeStarterPack,
|
activeStarterPack,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {isBlockedOrBlocking, isMuted} from '#/lib/moderation/blocked-and-muted'
|
|||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
||||||
import {getAllListMembers} from '#/state/queries/list-members'
|
import {getAllListMembers} from '#/state/queries/list-members'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useAppviewClient, useSession} from '#/state/session'
|
||||||
import {bulkWriteFollows} from '#/screens/Onboarding/util'
|
import {bulkWriteFollows} from '#/screens/Onboarding/util'
|
||||||
import {AvatarStack} from '#/screens/Search/components/StarterPackCard'
|
import {AvatarStack} from '#/screens/Search/components/StarterPackCard'
|
||||||
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
||||||
@@ -36,6 +36,7 @@ export function StarterPackCard({
|
|||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {gtPhone} = useBreakpoints()
|
const {gtPhone} = useBreakpoints()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const appviewClient = useAppviewClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const record = view.record
|
const record = view.record
|
||||||
const [isProcessing, setIsProcessing] = useState(false)
|
const [isProcessing, setIsProcessing] = useState(false)
|
||||||
@@ -48,7 +49,7 @@ export function StarterPackCard({
|
|||||||
|
|
||||||
let listItems: AppBskyGraphDefs.ListItemView[] = []
|
let listItems: AppBskyGraphDefs.ListItemView[] = []
|
||||||
try {
|
try {
|
||||||
listItems = await getAllListMembers(agent, view.list.uri)
|
listItems = await getAllListMembers(appviewClient, view.list.uri)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
Toast.show(_(msg`An error occurred while trying to follow all`), {
|
Toast.show(_(msg`An error occurred while trying to follow all`), {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import {
|
|||||||
useDeleteStarterPackMutation,
|
useDeleteStarterPackMutation,
|
||||||
useStarterPackQuery,
|
useStarterPackQuery,
|
||||||
} from '#/state/queries/starter-packs'
|
} from '#/state/queries/starter-packs'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useAppviewClient, useSession} from '#/state/session'
|
||||||
import {useSetActiveStarterPack} from '#/state/shell/landing'
|
import {useSetActiveStarterPack} from '#/state/shell/landing'
|
||||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||||
import {
|
import {
|
||||||
@@ -312,6 +312,7 @@ function Header({
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount, hasSession} = useSession()
|
const {currentAccount, hasSession} = useSession()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const appviewClient = useAppviewClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const setActiveStarterPack = useSetActiveStarterPack()
|
const setActiveStarterPack = useSetActiveStarterPack()
|
||||||
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
||||||
@@ -354,7 +355,7 @@ function Header({
|
|||||||
|
|
||||||
let listItems: AppBskyGraphDefs.ListItemView[] = []
|
let listItems: AppBskyGraphDefs.ListItemView[] = []
|
||||||
try {
|
try {
|
||||||
listItems = await getAllListMembers(agent, starterPack.list.uri)
|
listItems = await getAllListMembers(appviewClient, starterPack.list.uri)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
Toast.show(_(msg`An error occurred while trying to follow all`), {
|
Toast.show(_(msg`An error occurred while trying to follow all`), {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import {
|
import {type AppBskyActorDefs, type AppBskyGraphDefs} from '@atproto/api'
|
||||||
type AppBskyActorDefs,
|
import {type Client} from '@atproto/lex'
|
||||||
type AppBskyGraphDefs,
|
|
||||||
type AtpAgent,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import {type AtUriString} from '@atproto/syntax'
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
import {
|
import {
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
@@ -13,7 +10,7 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {useAgent, useAppviewClient} from '#/state/session'
|
import {useAppviewClient} from '#/state/session'
|
||||||
import {app} from '#/lexicons'
|
import {app} from '#/lexicons'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
@@ -50,36 +47,32 @@ export function useListMembersQuery(uri?: string, limit: number = PAGE_SIZE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useAllListMembersQuery(uri?: string) {
|
export function useAllListMembersQuery(uri?: string) {
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY_ALL(uri ?? ''),
|
queryKey: RQKEY_ALL(uri ?? ''),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
return getAllListMembers(agent, uri!)
|
return getAllListMembers(client, uri!)
|
||||||
},
|
},
|
||||||
enabled: Boolean(uri),
|
enabled: Boolean(uri),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
export async function getAllListMembers(client: Client, 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 hasMore = true
|
||||||
let cursor: string | undefined
|
let cursor: string | undefined
|
||||||
const listItems: AppBskyGraphDefs.ListItemView[] = []
|
const listItems: AppBskyGraphDefs.ListItemView[] = []
|
||||||
// We want to cap this at 6 pages, just for anything weird happening with the api
|
// We want to cap this at 6 pages, just for anything weird happening with the api
|
||||||
let i = 0
|
let i = 0
|
||||||
while (hasMore && i < 6) {
|
while (hasMore && i < 6) {
|
||||||
const res = await agent.app.bsky.graph.getList({
|
const res = await client.call(app.bsky.graph.getList, {
|
||||||
list: uri,
|
list: uri as AtUriString,
|
||||||
limit: 50,
|
limit: 50,
|
||||||
cursor,
|
cursor,
|
||||||
})
|
})
|
||||||
listItems.push(...res.data.items)
|
listItems.push(...res.items)
|
||||||
hasMore = Boolean(res.data.cursor)
|
hasMore = Boolean(res.cursor)
|
||||||
cursor = res.data.cursor
|
cursor = res.cursor
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return listItems
|
return listItems
|
||||||
|
|||||||
Reference in New Issue
Block a user