Skip to content

Commit

Permalink
fix: only grant badges if the user doesn't already have it
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kruse committed Dec 10, 2023
1 parent 984a75e commit 8be60f2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/cforum/jobs/vote_badge_distributor_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Cforum.Jobs.VoteBadgeDistributorJob do
defp grant_controverse_badge(owner, message) do
controverse = Badges.get_badge_by(slug: "controverse")

if message.upvotes >= 5 && message.downvotes >= 5 && !Users.badge?(owner, controverse),
if message.upvotes >= 5 && message.downvotes >= 5 && !Users.badge?(owner, controverse, false),
do: Badges.grant_badge(controverse, owner)
end

Expand Down Expand Up @@ -73,10 +73,10 @@ defmodule Cforum.Jobs.VoteBadgeDistributorJob do
enthusiast = Badges.get_badge_by(slug: "enthusiast")
critic = Badges.get_badge_by(slug: "critic")

if Helpers.present?(enthusiast) && vote.vtype == Vote.upvote() && !Users.badge?(user, enthusiast),
if Helpers.present?(enthusiast) && vote.vtype == Vote.upvote() && !Users.badge?(user, enthusiast, false),
do: Badges.grant_badge(enthusiast, user)

if Helpers.present?(critic) && vote.vtype == Vote.downvote() && !Users.badge?(user, critic),
if Helpers.present?(critic) && vote.vtype == Vote.downvote() && !Users.badge?(user, critic, false),
do: Badges.grant_badge(critic, user)

badge = Badges.get_badge_by(slug: "voter")
Expand Down Expand Up @@ -109,7 +109,7 @@ defmodule Cforum.Jobs.VoteBadgeDistributorJob do
|> Repo.all()

Enum.each(badges, fn b ->
if !Users.badge?(user, b),
if !Users.badge?(user, b, false),
do: Badges.grant_badge(b, user)
end)
end
Expand Down

0 comments on commit 8be60f2

Please sign in to comment.