about summary refs log tree commit diff
path: root/src/state/queries/my-muted-accounts.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-11-30 21:35:58 +0000
committerGitHub <noreply@github.com>2023-11-30 13:35:58 -0800
commit46b63accb8e73997f2a1bee24cfda220d29e048b (patch)
tree748de65b464e98d8241cc6fd8d11a9c17d9ec05c /src/state/queries/my-muted-accounts.ts
parent143fc80951d3a0620c0a5e55f46229f2fc743758 (diff)
downloadvoidsky-46b63accb8e73997f2a1bee24cfda220d29e048b.tar.zst
Rewrite the shadow logic to look inside the cache (#2045)
* Reset

* Associate shadows with the cache

* Use colocated helpers

* Fix types

* Reorder for clarity

* More types

* Copy paste logic for profile

* Hook up profile query

* Hook up suggested follows

* Hook up other profile things

* Fix shape

* Pass setShadow into the effect deps

* Include reply posts in the shadow cache search

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/state/queries/my-muted-accounts.ts')
-rw-r--r--src/state/queries/my-muted-accounts.ts32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/state/queries/my-muted-accounts.ts b/src/state/queries/my-muted-accounts.ts
index a175931b5..8929e04d3 100644
--- a/src/state/queries/my-muted-accounts.ts
+++ b/src/state/queries/my-muted-accounts.ts
@@ -1,5 +1,10 @@
-import {AppBskyGraphGetMutes} from '@atproto/api'
-import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
+import {AppBskyActorDefs, AppBskyGraphGetMutes} from '@atproto/api'
+import {
+  useInfiniteQuery,
+  InfiniteData,
+  QueryClient,
+  QueryKey,
+} from '@tanstack/react-query'
 
 import {getAgent} from '#/state/session'
 
@@ -26,3 +31,26 @@ export function useMyMutedAccountsQuery() {
     getNextPageParam: lastPage => lastPage.cursor,
   })
 }
+
+export function* findAllProfilesInQueryData(
+  queryClient: QueryClient,
+  did: string,
+): Generator<AppBskyActorDefs.ProfileView, void> {
+  const queryDatas = queryClient.getQueriesData<
+    InfiniteData<AppBskyGraphGetMutes.OutputSchema>
+  >({
+    queryKey: ['my-muted-accounts'],
+  })
+  for (const [_queryKey, queryData] of queryDatas) {
+    if (!queryData?.pages) {
+      continue
+    }
+    for (const page of queryData?.pages) {
+      for (const mute of page.mutes) {
+        if (mute.did === did) {
+          yield mute
+        }
+      }
+    }
+  }
+}