about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/state/cache/profile-shadow.ts4
-rw-r--r--src/state/queries/notifications/feed.ts27
-rw-r--r--src/state/queries/post-feed.ts39
-rw-r--r--src/state/queries/post-thread.ts49
-rw-r--r--src/state/queries/search-posts.ts33
-rw-r--r--src/view/com/posts/AviFollowButton.tsx8
6 files changed, 149 insertions, 11 deletions
diff --git a/src/state/cache/profile-shadow.ts b/src/state/cache/profile-shadow.ts
index 8d3e94042..0a618ab3b 100644
--- a/src/state/cache/profile-shadow.ts
+++ b/src/state/cache/profile-shadow.ts
@@ -9,8 +9,10 @@ import {findAllProfilesInQueryData as findAllProfilesInListMembersQueryData} fro
 import {findAllProfilesInQueryData as findAllProfilesInListConvosQueryData} from '../queries/messages/list-converations'
 import {findAllProfilesInQueryData as findAllProfilesInMyBlockedAccountsQueryData} from '../queries/my-blocked-accounts'
 import {findAllProfilesInQueryData as findAllProfilesInMyMutedAccountsQueryData} from '../queries/my-muted-accounts'
+import {findAllProfilesInQueryData as findAllProfilesInFeedsQueryData} from '../queries/post-feed'
 import {findAllProfilesInQueryData as findAllProfilesInPostLikedByQueryData} from '../queries/post-liked-by'
 import {findAllProfilesInQueryData as findAllProfilesInPostRepostedByQueryData} from '../queries/post-reposted-by'
+import {findAllProfilesInQueryData as findAllProfilesInPostThreadQueryData} from '../queries/post-thread'
 import {findAllProfilesInQueryData as findAllProfilesInProfileQueryData} from '../queries/profile'
 import {findAllProfilesInQueryData as findAllProfilesInProfileFollowersQueryData} from '../queries/profile-followers'
 import {findAllProfilesInQueryData as findAllProfilesInProfileFollowsQueryData} from '../queries/profile-follows'
@@ -107,4 +109,6 @@ function* findProfilesInCache(
   yield* findAllProfilesInSuggestedFollowsQueryData(queryClient, did)
   yield* findAllProfilesInActorSearchQueryData(queryClient, did)
   yield* findAllProfilesInListConvosQueryData(queryClient, did)
+  yield* findAllProfilesInFeedsQueryData(queryClient, did)
+  yield* findAllProfilesInPostThreadQueryData(queryClient, did)
 }
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts
index 523af2824..40be2ce8e 100644
--- a/src/state/queries/notifications/feed.ts
+++ b/src/state/queries/notifications/feed.ts
@@ -17,7 +17,7 @@
  */
 
 import {useEffect, useRef} from 'react'
-import {AppBskyFeedDefs} from '@atproto/api'
+import {AppBskyActorDefs, AppBskyFeedDefs} from '@atproto/api'
 import {
   InfiniteData,
   QueryClient,
@@ -162,3 +162,28 @@ export function* findAllPostsInQueryData(
     }
   }
 }
+
+export function* findAllProfilesInQueryData(
+  queryClient: QueryClient,
+  did: string,
+): Generator<AppBskyActorDefs.ProfileView, void> {
+  const queryDatas = queryClient.getQueriesData<InfiniteData<FeedPage>>({
+    queryKey: [RQKEY_ROOT],
+  })
+  for (const [_queryKey, queryData] of queryDatas) {
+    if (!queryData?.pages) {
+      continue
+    }
+    for (const page of queryData?.pages) {
+      for (const item of page.items) {
+        if (item.subject?.author.did === did) {
+          yield item.subject.author
+        }
+        const quotedPost = getEmbeddedPost(item.subject?.embed)
+        if (quotedPost?.author.did === did) {
+          yield quotedPost.author
+        }
+      }
+    }
+  }
+}
diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts
index eeec692c6..5c483483a 100644
--- a/src/state/queries/post-feed.ts
+++ b/src/state/queries/post-feed.ts
@@ -483,6 +483,45 @@ export function* findAllPostsInQueryData(
   }
 }
 
+export function* findAllProfilesInQueryData(
+  queryClient: QueryClient,
+  did: string,
+): Generator<AppBskyActorDefs.ProfileView, undefined> {
+  const queryDatas = queryClient.getQueriesData<
+    InfiniteData<FeedPageUnselected>
+  >({
+    queryKey: [RQKEY_ROOT],
+  })
+  for (const [_queryKey, queryData] of queryDatas) {
+    if (!queryData?.pages) {
+      continue
+    }
+    for (const page of queryData?.pages) {
+      for (const item of page.feed) {
+        if (item.post.author.did === did) {
+          yield item.post.author
+        }
+        const quotedPost = getEmbeddedPost(item.post.embed)
+        if (quotedPost?.author.did === did) {
+          yield quotedPost.author
+        }
+        if (
+          AppBskyFeedDefs.isPostView(item.reply?.parent) &&
+          item.reply?.parent?.author.did === did
+        ) {
+          yield item.reply.parent.author
+        }
+        if (
+          AppBskyFeedDefs.isPostView(item.reply?.root) &&
+          item.reply?.root?.author.did === did
+        ) {
+          yield item.reply.root.author
+        }
+      }
+    }
+  }
+}
+
 function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
   // no posts in this feed
   if (feed.length === 0) return true
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) {
diff --git a/src/state/queries/search-posts.ts b/src/state/queries/search-posts.ts
index 5bee96535..f71d64255 100644
--- a/src/state/queries/search-posts.ts
+++ b/src/state/queries/search-posts.ts
@@ -1,4 +1,8 @@
-import {AppBskyFeedDefs, AppBskyFeedSearchPosts} from '@atproto/api'
+import {
+  AppBskyActorDefs,
+  AppBskyFeedDefs,
+  AppBskyFeedSearchPosts,
+} from '@atproto/api'
 import {
   InfiniteData,
   QueryClient,
@@ -75,3 +79,30 @@ export function* findAllPostsInQueryData(
     }
   }
 }
+
+export function* findAllProfilesInQueryData(
+  queryClient: QueryClient,
+  did: string,
+): Generator<AppBskyActorDefs.ProfileView, undefined> {
+  const queryDatas = queryClient.getQueriesData<
+    InfiniteData<AppBskyFeedSearchPosts.OutputSchema>
+  >({
+    queryKey: [searchPostsQueryKeyRoot],
+  })
+  for (const [_queryKey, queryData] of queryDatas) {
+    if (!queryData?.pages) {
+      continue
+    }
+    for (const page of queryData?.pages) {
+      for (const post of page.posts) {
+        if (post.author.did === did) {
+          yield post.author
+        }
+        const quotedPost = getEmbeddedPost(post.embed)
+        if (quotedPost?.author.did === did) {
+          yield quotedPost.author
+        }
+      }
+    }
+  }
+}
diff --git a/src/view/com/posts/AviFollowButton.tsx b/src/view/com/posts/AviFollowButton.tsx
index 9358967e1..db15312a6 100644
--- a/src/view/com/posts/AviFollowButton.tsx
+++ b/src/view/com/posts/AviFollowButton.tsx
@@ -1,4 +1,4 @@
-import React, {useState} from 'react'
+import React from 'react'
 import {View} from 'react-native'
 import {AppBskyActorDefs, ModerationDecision} from '@atproto/api'
 import {msg} from '@lingui/macro'
@@ -39,7 +39,6 @@ export function AviFollowButton({
   })
   const gate = useGate()
   const {currentAccount, hasSession} = useSession()
-  const [followed, setFollowed] = useState<string | null>(null)
   const navigation = useNavigation<NavigationProp>()
 
   const name = sanitizeDisplayName(
@@ -47,13 +46,10 @@ export function AviFollowButton({
     moderation.ui('displayName'),
   )
   const isFollowing =
-    profile.viewer?.following ||
-    profile.did === followed ||
-    profile.did === currentAccount?.did
+    profile.viewer?.following || profile.did === currentAccount?.did
 
   function onPress() {
     follow()
-    setFollowed(profile.did)
     Toast.show(_(msg`Following ${name}`))
   }