FIX: `acted` state in post action like could desync with multiple likes (#16847)

If userA has multiple tab/devices on the same topic, and:

1. userA likes a post in tab1
2. userB likes the same post
3. userA post like `acted` attr would desync in tab2

This fix handles this case and also the reverse one when removing likes
interleaved with other users acting on the same post.

Reported in Meta at https://meta.discourse.org/t/-/227239/3
This commit is contained in:
Rafael dos Santos Silva 2022-05-17 10:21:17 -03:00 committed by GitHub
parent 28affa8cba
commit 5f1c3b4c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -356,7 +356,8 @@ const Post = RestModel.extend({
},
updateLikeCount(count, userId, eventType) {
let ownLike = User.current()?.id === userId && eventType === "liked";
let ownAction = User.current()?.id === userId;
let ownLike = ownAction && eventType === "liked";
let current_actions_summary = this.get("actions_summary");
let likeActionID = Site.current().post_action_types.find(
(a) => a.name_key === "like"
@ -375,6 +376,10 @@ const Post = RestModel.extend({
this.set("actionByName", json.actionByName);
this.set("likeAction", json.likeAction);
} else {
newActionObject.acted =
(ownLike || this.likeAction.acted) &&
!(eventType === "unliked" && ownAction);
Object.assign(
this.actions_summary.find((entry) => entry.id === likeActionID),
newActionObject