From 5f1c3b4c9f73d8128c41bd6889be9095dd80c17b Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Tue, 17 May 2022 10:21:17 -0300 Subject: [PATCH] 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 --- app/assets/javascripts/discourse/app/models/post.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js index 0d52a034721..7a046340899 100644 --- a/app/assets/javascripts/discourse/app/models/post.js +++ b/app/assets/javascripts/discourse/app/models/post.js @@ -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