about summary refs log tree commit diff
path: root/src/state
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-09-13 15:01:09 +0100
committerGitHub <noreply@github.com>2024-09-13 15:01:09 +0100
commit1dc7ef137cb7a546b1c84c1e7304a4f74ea1e66b (patch)
tree424cc08e9a7165449361d77afa0cb82b17179e86 /src/state
parent0315814eddca8af027f855cd8cfc9f139004c162 (diff)
downloadvoidsky-1dc7ef137cb7a546b1c84c1e7304a4f74ea1e66b.tar.zst
Fix notification->post jump for real (#5314)
* Revert "Fix notification scroll jump (#5297)"

This reverts commit e0d9e75407b053dd3b7a3472f925d8cd4bd92d45.

* Query notifications first
Diffstat (limited to 'src/state')
-rw-r--r--src/state/queries/notifications/util.ts19
-rw-r--r--src/state/queries/post-thread.ts8
2 files changed, 6 insertions, 21 deletions
diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts
index 133d3ebc2..e0ee02294 100644
--- a/src/state/queries/notifications/util.ts
+++ b/src/state/queries/notifications/util.ts
@@ -175,19 +175,9 @@ async function fetchSubjects(
 }> {
   const postUris = new Set<string>()
   const packUris = new Set<string>()
-
-  const postUrisWithLikes = new Set<string>()
-  const postUrisWithReposts = new Set<string>()
-
   for (const notif of groupedNotifs) {
     if (notif.subjectUri?.includes('app.bsky.feed.post')) {
       postUris.add(notif.subjectUri)
-      if (notif.type === 'post-like') {
-        postUrisWithLikes.add(notif.subjectUri)
-      }
-      if (notif.type === 'repost') {
-        postUrisWithReposts.add(notif.subjectUri)
-      }
     } else if (
       notif.notification.reasonSubject?.includes('app.bsky.graph.starterpack')
     ) {
@@ -216,15 +206,6 @@ async function fetchSubjects(
       AppBskyFeedPost.validateRecord(post.record).success
     ) {
       postsMap.set(post.uri, post)
-
-      // HACK. In some cases, the appview appears to lag behind and returns empty counters.
-      // To prevent scroll jump due to missing metrics, fill in 1 like/repost instead of 0.
-      if (post.likeCount === 0 && postUrisWithLikes.has(post.uri)) {
-        post.likeCount = 1
-      }
-      if (post.repostCount === 0 && postUrisWithReposts.has(post.uri)) {
-        post.repostCount = 1
-      }
     }
   }
   for (const pack of packsChunks.flat()) {
diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts
index 83ca60c2a..a569cb160 100644
--- a/src/state/queries/post-thread.ts
+++ b/src/state/queries/post-thread.ts
@@ -408,10 +408,14 @@ export function* findAllPostsInQueryData(
       }
     }
   }
-  for (let post of findAllPostsInFeedQueryData(queryClient, uri)) {
+  for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) {
+    // Check notifications first. If you have a post in notifications,
+    // it's often due to a like or a repost, and we want to prioritize
+    // a post object with >0 likes/reposts over a stale version with no
+    // metrics in order to avoid a notification->post scroll jump.
     yield postViewToPlaceholderThread(post)
   }
-  for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) {
+  for (let post of findAllPostsInFeedQueryData(queryClient, uri)) {
     yield postViewToPlaceholderThread(post)
   }
   for (let post of findAllPostsInQuoteQueryData(queryClient, uri)) {