Fix optimistic like/repost (#3503)
parent
f3951f2718
commit
7047755c50
|
@ -62,25 +62,29 @@ function mergeShadow(
|
||||||
return POST_TOMBSTONE
|
return POST_TOMBSTONE
|
||||||
}
|
}
|
||||||
|
|
||||||
const wasLiked = !!post.viewer?.like
|
|
||||||
const isLiked = !!shadow.likeUri
|
|
||||||
let likeCount = post.likeCount ?? 0
|
let likeCount = post.likeCount ?? 0
|
||||||
if (wasLiked && !isLiked) {
|
if ('likeUri' in shadow) {
|
||||||
likeCount--
|
const wasLiked = !!post.viewer?.like
|
||||||
} else if (!wasLiked && isLiked) {
|
const isLiked = !!shadow.likeUri
|
||||||
likeCount++
|
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
|
let repostCount = post.repostCount ?? 0
|
||||||
if (wasReposted && !isReposted) {
|
if ('repostUri' in shadow) {
|
||||||
repostCount--
|
const wasReposted = !!post.viewer?.repost
|
||||||
} else if (!wasReposted && isReposted) {
|
const isReposted = !!shadow.repostUri
|
||||||
repostCount++
|
if (wasReposted && !isReposted) {
|
||||||
|
repostCount--
|
||||||
|
} else if (!wasReposted && isReposted) {
|
||||||
|
repostCount++
|
||||||
|
}
|
||||||
|
repostCount = Math.max(0, repostCount)
|
||||||
}
|
}
|
||||||
repostCount = Math.max(0, repostCount)
|
|
||||||
|
|
||||||
return castAsShadow({
|
return castAsShadow({
|
||||||
...post,
|
...post,
|
||||||
|
|
Loading…
Reference in New Issue