Files
bsky-social-app/src/state/queries/messages/list-join-requests.ts
T
Samuel Newman 8da13e7511 drop the casts the dual-world layer needed
With every producer on the generated lexicons, the branded-string assertions at
these 30 sites are no-ops, and oxlint flags them. Also sorts the imports the
type flip disturbed and prunes the suppressions that no longer occur.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 22:13:50 +03:00

69 lines
2.0 KiB
TypeScript

import {useEffect} from 'react'
import {useInfiniteQuery, useQueryClient} from '@tanstack/react-query'
import {useMessagesEventBus} from '#/state/messages/events'
import {createQueryKey} from '#/state/queries/util'
import {useChatClient} from '#/state/session'
import {chat} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {STALE} from '..'
export const JOIN_REQUESTS_THRESHOLD = 20
const listJoinRequestsQueryKeyRoot = 'list-join-requests'
export const createListJoinRequestsQueryKey = (args: {convoId: string}) =>
createQueryKey(listJoinRequestsQueryKeyRoot, args)
export function useListJoinRequestsQuery({
convoId,
enabled,
}: {
convoId: string | undefined
enabled?: boolean
}) {
const client = useChatClient()
const queryClient = useQueryClient()
const messagesBus = useMessagesEventBus()
const isEnabled = enabled !== false && !!convoId
useEffect(() => {
if (!isEnabled || !convoId) return
return messagesBus.on(
event => {
if (event.type !== 'logs') return
for (const log of event.logs) {
if (
bsky.isType(chat.bsky.convo.defs.logIncomingJoinRequest, log) ||
bsky.isType(chat.bsky.convo.defs.logApproveJoinRequest, log) ||
bsky.isType(chat.bsky.convo.defs.logRejectJoinRequest, log)
) {
void queryClient.invalidateQueries({
queryKey: createListJoinRequestsQueryKey({convoId}),
})
return
}
}
},
{convoId},
)
}, [isEnabled, convoId, messagesBus, queryClient])
return useInfiniteQuery({
enabled: isEnabled,
queryKey: createListJoinRequestsQueryKey({convoId: convoId ?? ''}),
queryFn: async ({pageParam}) => {
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,
staleTime: STALE.MINUTES.ONE,
})
}