Skip to content

Commit

Permalink
Fix optimistic like/repost (#3503)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Apr 12, 2024
1 parent f3951f2 commit 7047755
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/state/cache/post-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7047755

Please sign in to comment.