enqueue_communicate_facebook_job.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Schedules a backgrond communication job for new facebook articles.
  3. module Ticket::Article::EnqueueCommunicateFacebookJob
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_article_enqueue_communicate_facebook_job
  7. end
  8. private
  9. def ticket_article_enqueue_communicate_facebook_job
  10. # return if we run import mode
  11. return true if Setting.get('import_mode')
  12. # only do send email if article got created via application_server (e. g. not
  13. # if article and sender type is set via *.postmaster)
  14. return true if ApplicationHandleInfo.postmaster?
  15. # if sender is customer, do not communicate
  16. return true if !sender_id
  17. sender = Ticket::Article::Sender.lookup(id: sender_id)
  18. return true if sender.nil?
  19. return true if sender.name == 'Customer'
  20. # only apply for facebook
  21. return true if !type_id
  22. type = Ticket::Article::Type.lookup(id: type_id)
  23. return true if type.nil?
  24. return true if !type.name.start_with?('facebook')
  25. CommunicateFacebookJob.perform_later(id)
  26. end
  27. end