discourse-ai/lib/modules/toxicity/scan_queue.rb

28 lines
732 B
Ruby
Raw Normal View History

2023-02-22 18:46:53 -05:00
# frozen_string_literal: true
module ::DiscourseAI
module Toxicity
class ScanQueue
2023-02-22 18:46:53 -05:00
class << self
def enqueue_post(post)
2023-02-22 18:46:53 -05:00
return if bypass?(post)
Jobs.enqueue(:toxicity_classify_post, post_id: post.id)
end
def enqueue_chat_message(chat_message)
2023-02-22 18:46:53 -05:00
return if bypass?(chat_message)
Jobs.enqueue(:toxicity_classify_chat_message, chat_message_id: chat_message.id)
end
def bypass?(content)
!SiteSetting.ai_toxicity_enabled || group_bypass?(content.user)
end
def group_bypass?(user)
user.groups.pluck(:id).intersection(SiteSetting.ai_toxicity_groups_bypass_map).present?
2023-02-22 18:46:53 -05:00
end
end
end
end
end