migrate the join link and join request queries to the chat client
The logged-out join link preview path built an ad-hoc AtpAgent pointed at CHAT_SERVICE. It is now a module-level unauthenticated lex client against the same service, so the client is built once rather than per call. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,10 @@ import {useEffect} from 'react'
|
||||
import {ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {useInfiniteQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {DM_SERVICE_HEADERS} from '#/lib/constants'
|
||||
import {useMessagesEventBus} from '#/state/messages/events'
|
||||
import {createQueryKey} from '#/state/queries/util'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useChatClient} from '#/state/session'
|
||||
import {chat} from '#/lexicons'
|
||||
import {STALE} from '..'
|
||||
|
||||
export const JOIN_REQUESTS_THRESHOLD = 20
|
||||
@@ -22,7 +22,7 @@ export function useListJoinRequestsQuery({
|
||||
convoId: string | undefined
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const agent = useAgent()
|
||||
const client = useChatClient()
|
||||
const queryClient = useQueryClient()
|
||||
const messagesBus = useMessagesEventBus()
|
||||
const isEnabled = enabled !== false && !!convoId
|
||||
@@ -54,11 +54,12 @@ export function useListJoinRequestsQuery({
|
||||
enabled: isEnabled,
|
||||
queryKey: createListJoinRequestsQueryKey({convoId: convoId ?? ''}),
|
||||
queryFn: async ({pageParam}) => {
|
||||
const {data} = await agent.chat.bsky.group.listJoinRequests(
|
||||
{convoId: convoId!, cursor: pageParam, limit: JOIN_REQUESTS_THRESHOLD},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
return data
|
||||
return await client.call(chat.bsky.group.listJoinRequests, {
|
||||
// guarded by `isEnabled`
|
||||
convoId: convoId!,
|
||||
cursor: pageParam,
|
||||
limit: JOIN_REQUESTS_THRESHOLD,
|
||||
})
|
||||
},
|
||||
initialPageParam: undefined as string | undefined,
|
||||
getNextPageParam: page => page.cursor,
|
||||
|
||||
Reference in New Issue
Block a user