online_notification_seen.rb 875 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::OnlineNotificationSeen < ActiveRecord::Observer
  3. observe 'ticket'
  4. def after_create(record)
  5. _check(record)
  6. end
  7. def after_update(record)
  8. _check(record)
  9. end
  10. private
  11. def _check(record)
  12. # return if we run import mode
  13. return false if Setting.get('import_mode')
  14. # set seen only if state has changes
  15. return false if !record.saved_changes?
  16. return false if record.saved_changes['state_id'].blank?
  17. # check if existing online notifications for this ticket should be set to seen
  18. return true if !record.online_notification_seen_state
  19. # set all online notifications to seen
  20. # send background job
  21. Delayed::Job.enqueue(Observer::Ticket::OnlineNotificationSeen::BackgroundJob.new(record.id, record.updated_by_id))
  22. end
  23. end