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

Configure Feed

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

at main 75 lines 2.1 kB view raw
1import { 2 type AppBskyActorDefs, 3 type AppBskyUnspeccedGetSuggestedUsersForDiscover, 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 {getContentLanguages} from '#/state/preferences/languages' 12import {STALE} from '#/state/queries' 13import {usePreferencesQuery} from '#/state/queries/preferences' 14import {useAgent} from '#/state/session' 15 16export type QueryProps = { 17 limit?: number 18} 19 20export const getSuggestedUsersForDiscoverQueryKeyRoot = 21 'unspecced-suggested-users-for-explore' 22export const createGetSuggestedUsersForDiscoverQueryKey = ( 23 props: QueryProps, 24) => [getSuggestedUsersForDiscoverQueryKeyRoot, props.limit] 25 26export function useGetSuggestedUsersForDiscoverQuery(props: QueryProps = {}) { 27 const agent = useAgent() 28 const {data: preferences} = usePreferencesQuery() 29 30 return useQuery({ 31 staleTime: STALE.MINUTES.THREE, 32 queryKey: createGetSuggestedUsersForDiscoverQueryKey(props), 33 queryFn: async () => { 34 const contentLangs = getContentLanguages().join(',') 35 const userInterests = aggregateUserInterests(preferences) 36 37 const {data} = 38 await agent.app.bsky.unspecced.getSuggestedUsersForDiscover( 39 { 40 limit: props.limit || 10, 41 }, 42 { 43 headers: { 44 ...createBskyTopicsHeader(userInterests), 45 'Accept-Language': contentLangs, 46 }, 47 }, 48 ) 49 return {...data, recId: data.recIdStr} 50 }, 51 }) 52} 53 54export function* findAllProfilesInQueryData( 55 queryClient: QueryClient, 56 did: string, 57): Generator<AppBskyActorDefs.ProfileView, void> { 58 const responses = 59 queryClient.getQueriesData<AppBskyUnspeccedGetSuggestedUsersForDiscover.OutputSchema>( 60 { 61 queryKey: [getSuggestedUsersForDiscoverQueryKeyRoot], 62 }, 63 ) 64 for (const [_key, response] of responses) { 65 if (!response) { 66 continue 67 } 68 69 for (const actor of response.actors) { 70 if (actor.did === did) { 71 yield actor 72 } 73 } 74 } 75}