From e0d9e75407b053dd3b7a3472f925d8cd4bd92d45 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 12 Sep 2024 15:39:04 +0100 Subject: [PATCH] Fix notification scroll jump (#5297) --- src/state/queries/notifications/util.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index e0ee0229..133d3ebc 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -175,9 +175,19 @@ async function fetchSubjects( }> { const postUris = new Set() const packUris = new Set() + + const postUrisWithLikes = new Set() + const postUrisWithReposts = new Set() + 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') ) { @@ -206,6 +216,15 @@ 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()) {