mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 13:05:17 +08:00
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:
parent
21abcfe5a7
commit
b160331d41
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user