Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Do not show Likes on reactions-received endpoint #279

Merged
merged 1 commit into from Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -109,13 +109,22 @@ def reactions_received
reaction_users = reaction_users.order(created_at: :desc).limit(20).to_a

if params[:include_likes]
# We do not want to include likes that also count as
# a reaction, otherwise it is confusing in the UI. We
# do the same on the likes-received endpoint.
likes =
PostAction
.where(
post_id: post_ids,
deleted_at: nil,
post_action_type_id: PostActionType.types[:like],
)
.joins(<<~SQL)
LEFT JOIN discourse_reactions_reaction_users ON
discourse_reactions_reaction_users.post_id = post_actions.post_id
AND discourse_reactions_reaction_users.user_id = post_actions.user_id
SQL
.where("discourse_reactions_reaction_users.id IS NULL")
.order(created_at: :desc)
.limit(20)

Expand Down
26 changes: 26 additions & 0 deletions spec/requests/custom_reactions_controller_spec.rb
Expand Up @@ -349,6 +349,32 @@
expect(parsed[0]["reaction"]["id"]).to eq(like.id)
end

it "does not include reactions which also count as a like when include_likes is true" do
sign_in(user_1)
other_post = Fabricate(:post, user: user_1)
laugh = Fabricate(:reaction_user, reaction: laughing_reaction, user: user_5, post: other_post)

get "/discourse-reactions/posts/reactions-received.json",
params: {
username: user_1.username,
include_likes: true,
acting_username: user_5.username,
}

parsed = response.parsed_body
expect(parsed.size).to eq(2)

expect(parsed[0]["user"]["id"]).to eq(user_5.id)
expect(parsed[0]["post_id"]).to eq(other_post.id)
expect(parsed[0]["post"]["user"]["id"]).to eq(user_1.id)
expect(parsed[0]["reaction"]["id"]).to eq(laugh.reaction.id)

expect(parsed[1]["user"]["id"]).to eq(user_5.id)
expect(parsed[1]["post_id"]).to eq(post_2.id)
expect(parsed[1]["post"]["user"]["id"]).to eq(user_1.id)
expect(parsed[1]["reaction"]["id"]).to eq(like.id)
end

it "also filter likes by id when including likes" do
latest_like =
Fabricate(
Expand Down