communicate_facebook.rb 975 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # return if we run import mode
  6. return if Setting.get('import_mode')
  7. # only do send email if article got created via application_server (e. g. not
  8. # if article and sender type is set via *.postmaster)
  9. return if ApplicationHandleInfo.postmaster?
  10. # if sender is customer, do not communicate
  11. return if !record.sender_id
  12. sender = Ticket::Article::Sender.lookup(id: record.sender_id)
  13. return 1 if sender.nil?
  14. return 1 if sender['name'] == 'Customer'
  15. # only apply for facebook
  16. return if !record.type_id
  17. type = Ticket::Article::Type.lookup(id: record.type_id)
  18. return if type['name'] !~ /\Afacebook/
  19. Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateFacebook::BackgroundJob.new(record.id))
  20. end
  21. end