Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at theme-changes 87 lines 2.5 kB view raw
1import { 2 type AppBskyActorDefs, 3 type AppBskyUnspeccedGetSuggestedUsersForSeeMore, 4} from '@atproto/api' 5import {type QueryClient, useQuery} from '@tanstack/react-query' 6 7import { 8 aggregateUserInterests, 9 createBskyTopicsHeader, 10} from '#/lib/api/feed/utils' 11import {logger} from '#/logger' 12import {getContentLanguages} from '#/state/preferences/languages' 13import {STALE} from '#/state/queries' 14import {usePreferencesQuery} from '#/state/queries/preferences' 15import {useAgent} from '#/state/session' 16 17export type QueryProps = { 18 category?: string | null 19 limit?: number 20 enabled?: boolean 21} 22 23export const getSuggestedUsersForSeeMoreQueryKeyRoot = 24 'unspecced-suggested-users-for-explore' 25export const createGetSuggestedUsersForSeeMoreQueryKey = (props: { 26 category?: string | null 27 limit?: number 28}) => [getSuggestedUsersForSeeMoreQueryKeyRoot, props.category, props.limit] 29 30export function useGetSuggestedUsersForSeeMoreQuery(props: QueryProps = {}) { 31 const agent = useAgent() 32 const {data: preferences} = usePreferencesQuery() 33 34 return useQuery({ 35 enabled: props.enabled ?? true, 36 staleTime: STALE.MINUTES.THREE, 37 queryKey: createGetSuggestedUsersForSeeMoreQueryKey({ 38 category: props.category, 39 limit: props.limit, 40 }), 41 queryFn: async () => { 42 const contentLangs = getContentLanguages().join(',') 43 const userInterests = aggregateUserInterests(preferences) 44 45 const {data} = await agent.app.bsky.unspecced.getSuggestedUsersForSeeMore( 46 { 47 category: props.category ?? undefined, 48 limit: props.limit || 50, 49 }, 50 { 51 headers: { 52 ...createBskyTopicsHeader(userInterests), 53 'Accept-Language': contentLangs, 54 }, 55 }, 56 ) 57 58 if (!data.recIdStr) { 59 logger.debug('getSuggestedUsersForSeeMore response missing recIdStr') 60 } 61 return {...data, recId: data.recIdStr} 62 }, 63 }) 64} 65 66export function* findAllProfilesInQueryData( 67 queryClient: QueryClient, 68 did: string, 69): Generator<AppBskyActorDefs.ProfileView, void> { 70 const responses = 71 queryClient.getQueriesData<AppBskyUnspeccedGetSuggestedUsersForSeeMore.OutputSchema>( 72 { 73 queryKey: [getSuggestedUsersForSeeMoreQueryKeyRoot], 74 }, 75 ) 76 for (const [_key, response] of responses) { 77 if (!response) { 78 continue 79 } 80 81 for (const actor of response.actors) { 82 if (actor.did === did) { 83 yield actor 84 } 85 } 86 } 87}