8da13e7511
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>
69 lines
2.0 KiB
TypeScript
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,
|
|
})
|
|
}
|