[APP-2864] Use hydrated known likers (#11541)
This commit is contained in:
@@ -4,11 +4,8 @@ import {
|
||||
type QueryClient,
|
||||
type QueryKey,
|
||||
useInfiniteQuery,
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {createQueryKey} from '#/state/queries/util'
|
||||
import {useAppviewClient} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
|
||||
@@ -43,42 +40,6 @@ export function useLikedByQuery(resolvedUri: string | undefined) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum `limit` accepted by `app.bsky.feed.getLikes` in a single
|
||||
* request.
|
||||
*/
|
||||
const SAMPLE_SIZE = 100
|
||||
|
||||
const likedBySampleQueryKeyRoot = 'liked-by-sample'
|
||||
export const createLikedBySampleQueryKey = (args: {uri: string}) =>
|
||||
createQueryKey(likedBySampleQueryKeyRoot, args)
|
||||
|
||||
/**
|
||||
* A single-request sample of a post's most recent likers, as many as the API
|
||||
* allows in one page (100). Used for the known-likers social proof on the
|
||||
* post thread page. Kept separate from `useLikedByQuery` so it does not
|
||||
* perturb the liked-by screen's pagination.
|
||||
*/
|
||||
export function useLikedBySampleQuery({uri}: {uri: string | undefined}) {
|
||||
const client = useAppviewClient()
|
||||
return useQuery({
|
||||
queryKey: createLikedBySampleQueryKey({uri: uri ?? ''}),
|
||||
queryFn: async () => {
|
||||
return await client.call(app.bsky.feed.getLikes, {
|
||||
uri: (uri ?? '') as AtUriString,
|
||||
limit: SAMPLE_SIZE,
|
||||
})
|
||||
},
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
enabled: !!uri,
|
||||
/*
|
||||
* Consumers fall back to a plain like count when this query fails, so
|
||||
* failing fast is preferable to amplifying getLikes load with retries.
|
||||
*/
|
||||
retry: 1,
|
||||
})
|
||||
}
|
||||
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
@@ -100,18 +61,4 @@ export function* findAllProfilesInQueryData(
|
||||
}
|
||||
}
|
||||
}
|
||||
const sampleQueryDatas =
|
||||
queryClient.getQueriesData<app.bsky.feed.getLikes.$OutputBody>({
|
||||
queryKey: [likedBySampleQueryKeyRoot],
|
||||
})
|
||||
for (const [_queryKey, queryData] of sampleQueryDatas) {
|
||||
if (!queryData?.likes) {
|
||||
continue
|
||||
}
|
||||
for (const like of queryData.likes) {
|
||||
if (like.actor.did === did) {
|
||||
yield like.actor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +325,12 @@ export function* findAllProfilesInQueryData(
|
||||
yield item.value.post.author
|
||||
}
|
||||
|
||||
for (const actor of item.value.post.viewer?.knownLikers?.actors ?? []) {
|
||||
if (actor.did === did) {
|
||||
yield actor
|
||||
}
|
||||
}
|
||||
|
||||
const qp = getEmbeddedPost(item.value.post.embed)
|
||||
if (qp && qp.author.did === did) {
|
||||
yield qp.author
|
||||
|
||||
Reference in New Issue
Block a user