2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2015-08-28 00:53:14 +00:00
|
|
|
require 'channel/driver/facebook'
|
2015-07-09 14:56:01 +00:00
|
|
|
|
2012-12-24 13:55:43 +00:00
|
|
|
class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
# only do send email if article got created via application_server (e. g. not
|
|
|
|
# if article and sender type is set via *.postmaster)
|
|
|
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
|
|
|
|
|
|
|
# if sender is customer, do not communicate
|
2016-08-23 18:46:04 +00:00
|
|
|
return if !record.sender_id
|
2016-01-16 00:16:31 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
2015-05-07 10:11:45 +00:00
|
|
|
return 1 if sender.nil?
|
2012-12-24 13:55:43 +00:00
|
|
|
return 1 if sender['name'] == 'Customer'
|
|
|
|
|
2015-07-09 14:56:01 +00:00
|
|
|
# only apply for facebook
|
2016-08-23 18:46:04 +00:00
|
|
|
return if !record.type_id
|
2016-01-16 00:16:31 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
2015-07-09 14:56:01 +00:00
|
|
|
return if type['name'] !~ /\Afacebook/
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2016-06-25 21:18:06 +00:00
|
|
|
Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateFacebook::BackgroundJob.new(record.id))
|
2012-12-24 13:55:43 +00:00
|
|
|
end
|
2016-06-25 21:18:06 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|