Add optimisticReplyCount to post shadow
This commit is contained in:
Vendored
+8
-1
@@ -24,12 +24,13 @@ export interface PostShadow {
|
|||||||
isDeleted: boolean
|
isDeleted: boolean
|
||||||
embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined
|
embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined
|
||||||
pinned: boolean
|
pinned: boolean
|
||||||
|
optimisticReplyCount: number | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST_TOMBSTONE = Symbol('PostTombstone')
|
export const POST_TOMBSTONE = Symbol('PostTombstone')
|
||||||
|
|
||||||
const emitter = new EventEmitter()
|
const emitter = new EventEmitter()
|
||||||
const shadows: WeakMap<
|
export const shadows: WeakMap<
|
||||||
AppBskyFeedDefs.PostView,
|
AppBskyFeedDefs.PostView,
|
||||||
Partial<PostShadow>
|
Partial<PostShadow>
|
||||||
> = new WeakMap()
|
> = new WeakMap()
|
||||||
@@ -95,6 +96,11 @@ function mergeShadow(
|
|||||||
repostCount = Math.max(0, repostCount)
|
repostCount = Math.max(0, repostCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let replyCount = post.replyCount ?? 0
|
||||||
|
if ('optimisticReplyCount' in shadow) {
|
||||||
|
replyCount = shadow.optimisticReplyCount ?? replyCount
|
||||||
|
}
|
||||||
|
|
||||||
let embed: typeof post.embed
|
let embed: typeof post.embed
|
||||||
if ('embed' in shadow) {
|
if ('embed' in shadow) {
|
||||||
if (
|
if (
|
||||||
@@ -112,6 +118,7 @@ function mergeShadow(
|
|||||||
embed: embed || post.embed,
|
embed: embed || post.embed,
|
||||||
likeCount: likeCount,
|
likeCount: likeCount,
|
||||||
repostCount: repostCount,
|
repostCount: repostCount,
|
||||||
|
replyCount: replyCount,
|
||||||
viewer: {
|
viewer: {
|
||||||
...(post.viewer || {}),
|
...(post.viewer || {}),
|
||||||
like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like,
|
like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {type QueryClient} from '@tanstack/react-query'
|
import {type QueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {shadows, updatePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews'
|
import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews'
|
||||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed'
|
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed'
|
||||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed'
|
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed'
|
||||||
@@ -85,10 +86,13 @@ export function createCacheMutator({
|
|||||||
/*
|
/*
|
||||||
* Update parent data
|
* Update parent data
|
||||||
*/
|
*/
|
||||||
parent.value.post = {
|
const shadow = shadows.get(parent.value.post)
|
||||||
...parent.value.post,
|
const prevOptimisticCount = shadow?.optimisticReplyCount || 0
|
||||||
replyCount: (parent.value.post.replyCount || 0) + 1,
|
const prevReplyCount = parent.value.post.replyCount || 0
|
||||||
}
|
updatePostShadow(queryClient, parent.value.post.uri, {
|
||||||
|
// prefer optimistic count, if we already have some
|
||||||
|
optimisticReplyCount: (prevOptimisticCount || prevReplyCount) + 1,
|
||||||
|
})
|
||||||
|
|
||||||
const opDid = getRootPostAtUri(parent.value.post)?.host
|
const opDid = getRootPostAtUri(parent.value.post)?.host
|
||||||
const nextPreexistingItem = thread.at(i + 1)
|
const nextPreexistingItem = thread.at(i + 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user