diff options
author | dan <dan.abramov@gmail.com> | 2024-04-12 16:39:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 16:39:59 +0100 |
commit | 7047755c509716a6ab1d63ffef24dd9540a88915 (patch) | |
tree | 0caa61b8f122fe1c7bd65a531526e13d40ee082c /src/state/cache | |
parent | f3951f2718307ddbe1a4a90c599f777359513e4d (diff) | |
download | voidsky-7047755c509716a6ab1d63ffef24dd9540a88915.tar.zst |
Fix optimistic like/repost (#3503)
Diffstat (limited to 'src/state/cache')
-rw-r--r-- | src/state/cache/post-shadow.ts | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/state/cache/post-shadow.ts b/src/state/cache/post-shadow.ts index 6225cbdba..48183739b 100644 --- a/src/state/cache/post-shadow.ts +++ b/src/state/cache/post-shadow.ts @@ -62,25 +62,29 @@ function mergeShadow( return POST_TOMBSTONE } - const wasLiked = !!post.viewer?.like - const isLiked = !!shadow.likeUri let likeCount = post.likeCount ?? 0 - if (wasLiked && !isLiked) { - likeCount-- - } else if (!wasLiked && isLiked) { - likeCount++ + if ('likeUri' in shadow) { + const wasLiked = !!post.viewer?.like + const isLiked = !!shadow.likeUri + if (wasLiked && !isLiked) { + likeCount-- + } else if (!wasLiked && isLiked) { + likeCount++ + } + likeCount = Math.max(0, likeCount) } - likeCount = Math.max(0, likeCount) - const wasReposted = !!post.viewer?.repost - const isReposted = !!shadow.repostUri let repostCount = post.repostCount ?? 0 - if (wasReposted && !isReposted) { - repostCount-- - } else if (!wasReposted && isReposted) { - repostCount++ + if ('repostUri' in shadow) { + const wasReposted = !!post.viewer?.repost + const isReposted = !!shadow.repostUri + if (wasReposted && !isReposted) { + repostCount-- + } else if (!wasReposted && isReposted) { + repostCount++ + } + repostCount = Math.max(0, repostCount) } - repostCount = Math.max(0, repostCount) return castAsShadow({ ...post, |