FIX: Move show like logic to client side (#18025)

The logic was added in commit ec8306835d,
to show the like action even if the user could not like the post. It is
not necessary for this logic to be implemented on the server side.
This commit is contained in:
Bianca Nenciu 2022-08-22 18:40:09 +03:00 committed by GitHub
parent 21abcfe5a7
commit b160331d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 12 deletions

View File

@ -255,9 +255,12 @@ export default function transformPost(
if (likeAction) { if (likeAction) {
postAtts.liked = likeAction.acted; postAtts.liked = likeAction.acted;
postAtts.canToggleLike = likeAction.get("canToggle"); postAtts.canToggleLike = likeAction.get("canToggle");
postAtts.showLike = true; postAtts.showLike = postAtts.liked || postAtts.canToggleLike;
postAtts.likeCount = likeAction.count; postAtts.likeCount = likeAction.count;
} else if (!currentUser) { } else if (
!currentUser ||
(topic.archived && topic.user_id !== currentUser.id)
) {
postAtts.showLike = true; postAtts.showLike = true;
} }

View File

@ -315,8 +315,7 @@ class PostSerializer < BasicPostSerializer
summary.delete(:count) if summary[:count] == 0 summary.delete(:count) if summary[:count] == 0
# Only include it if the user can do it or it has a count # Only include it if the user can do it or it has a count
# If it is a like, we want to show it always (even for archived topic) if summary[:can_act] || summary[:count]
if summary[:can_act] || summary[:count] || (sym == :like && object.user_id != scope.user&.id)
result << summary result << summary
end end
end end

View File

@ -55,14 +55,6 @@ RSpec.describe PostSerializer do
expect(notify_user_action).to eq(nil) expect(notify_user_action).to eq(nil)
end end
it "shows like for archived topics even if user cannot act" do
post = Fabricate(:post)
post.topic.update!(archived: true)
serializer = PostSerializer.new(post, scope: Guardian.new(actor), root: false)
expect(serializer.as_json[:actions_summary].map { |a| a[:id] }).to include(PostActionType.types[:like])
end
end end
context "with a post with reviewable content" do context "with a post with reviewable content" do