discourse-akismet/jobs/regular/check_akismet_post.rb
Juan David Martínez Cubillos 664cc3f828
FEATURE: Implement Akismet flag and review system for PostVotingComments (#112)
* FEATURE: Implement Akismet flag and review system for PostVotingComments

* polished bugs and completed reviewables implementation

* adding test plugin dependecies

* rubocop fix

* syntax tree fix

* deleted comments

* added requested changes

* linter fixes

* refactored #before_check in post voting bouncer
2024-01-11 16:04:57 -05:00

21 lines
659 B
Ruby

# frozen_string_literal: true
module Jobs
class CheckAkismetPost < ::Jobs::Base
def execute(args)
return if !SiteSetting.akismet_enabled?
return if !(post = Post.find_by(id: args[:post_id], user_deleted: false))
return if Reviewable.exists?(target: post)
DistributedMutex.synchronize("akismet_post_#{post.id}") do
if post.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE] ==
DiscourseAkismet::Bouncer::PENDING_STATE
DiscourseAkismet::PostsBouncer.new.perform_check(
DiscourseAkismet::AntiSpamService.client,
post,
)
end
end
end
end
end