diff options
author | Eric Bailey <git@esb.lol> | 2024-05-30 23:56:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-31 05:56:09 +0100 |
commit | d614f6cb71bf2751834dbd800b5f43257d5c074a (patch) | |
tree | f33f56f7daf3cb844bd45610eb24bf51326f5ffc /src/state/queries/post-thread.ts | |
parent | 89c9fd3be16ea96182842544d76ce019cb8e1403 (diff) | |
download | voidsky-d614f6cb71bf2751834dbd800b5f43257d5c074a.tar.zst |
Shadows (#4265)
Diffstat (limited to 'src/state/queries/post-thread.ts')
-rw-r--r-- | src/state/queries/post-thread.ts | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts index 6c70bbc5d..b1bff1493 100644 --- a/src/state/queries/post-thread.ts +++ b/src/state/queries/post-thread.ts @@ -1,4 +1,5 @@ import { + AppBskyActorDefs, AppBskyEmbedRecord, AppBskyFeedDefs, AppBskyFeedGetPostThread, @@ -11,9 +12,18 @@ import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query' import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' import {useAgent} from '#/state/session' -import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from 'state/queries/search-posts' -import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed' -import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed' +import { + findAllPostsInQueryData as findAllPostsInSearchQueryData, + findAllProfilesInQueryData as findAllProfilesInSearchQueryData, +} from 'state/queries/search-posts' +import { + findAllPostsInQueryData as findAllPostsInNotifsQueryData, + findAllProfilesInQueryData as findAllProfilesInNotifsQueryData, +} from './notifications/feed' +import { + findAllPostsInQueryData as findAllPostsInFeedQueryData, + findAllProfilesInQueryData as findAllProfilesInFeedQueryData, +} from './post-feed' import {embedViewRecordToPostView, getEmbeddedPost} from './util' const RQKEY_ROOT = 'post-thread' @@ -293,6 +303,39 @@ export function* findAllPostsInQueryData( } } +export function* findAllProfilesInQueryData( + queryClient: QueryClient, + did: string, +): Generator<AppBskyActorDefs.ProfileView, void> { + const queryDatas = queryClient.getQueriesData<ThreadNode>({ + queryKey: [RQKEY_ROOT], + }) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData) { + continue + } + for (const item of traverseThread(queryData)) { + if (item.type === 'post' && item.post.author.did === did) { + yield item.post.author + } + const quotedPost = + item.type === 'post' ? getEmbeddedPost(item.post.embed) : undefined + if (quotedPost?.author.did === did) { + yield quotedPost?.author + } + } + } + for (let profile of findAllProfilesInFeedQueryData(queryClient, did)) { + yield profile + } + for (let profile of findAllProfilesInNotifsQueryData(queryClient, did)) { + yield profile + } + for (let profile of findAllProfilesInSearchQueryData(queryClient, did)) { + yield profile + } +} + function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> { if (node.type === 'post') { if (node.parent) { |