diff options
Diffstat (limited to 'src/state/queries/suggested-follows.ts')
-rw-r--r-- | src/state/queries/suggested-follows.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/state/queries/suggested-follows.ts b/src/state/queries/suggested-follows.ts index eadcb590a..932226b75 100644 --- a/src/state/queries/suggested-follows.ts +++ b/src/state/queries/suggested-follows.ts @@ -1,5 +1,6 @@ import React from 'react' import { + AppBskyActorDefs, AppBskyActorGetSuggestions, AppBskyGraphGetSuggestedFollowsByActor, moderateProfile, @@ -9,6 +10,7 @@ import { useQueryClient, useQuery, InfiniteData, + QueryClient, QueryKey, } from '@tanstack/react-query' @@ -106,3 +108,56 @@ export function useGetSuggestedFollowersByActor() { [queryClient], ) } + +export function* findAllProfilesInQueryData( + queryClient: QueryClient, + did: string, +): Generator<AppBskyActorDefs.ProfileView, void> { + yield* findAllProfilesInSuggestedFollowsQueryData(queryClient, did) + yield* findAllProfilesInSuggestedFollowsByActorQueryData(queryClient, did) +} + +function* findAllProfilesInSuggestedFollowsQueryData( + queryClient: QueryClient, + did: string, +) { + const queryDatas = queryClient.getQueriesData< + InfiniteData<AppBskyActorGetSuggestions.OutputSchema> + >({ + queryKey: ['suggested-follows'], + }) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData?.pages) { + continue + } + for (const page of queryData?.pages) { + for (const actor of page.actors) { + if (actor.did === did) { + yield actor + } + } + } + } +} + +function* findAllProfilesInSuggestedFollowsByActorQueryData( + queryClient: QueryClient, + did: string, +) { + const queryDatas = + queryClient.getQueriesData<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema>( + { + queryKey: ['suggested-follows-by-actor'], + }, + ) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData) { + continue + } + for (const suggestion of queryData.suggestions) { + if (suggestion.did === did) { + yield suggestion + } + } + } +} |