sets_online_notification_seen.rb 933 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Schedules a background job to update the user's ticket seen information on ticket changes.
  3. module Ticket::SetsOnlineNotificationSeen
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_set_online_notification_seen
  7. after_update :ticket_set_online_notification_seen
  8. end
  9. private
  10. def ticket_set_online_notification_seen
  11. # return if we run import mode
  12. return false if Setting.get('import_mode')
  13. # set seen only if state has changes
  14. return false if !saved_changes?
  15. return false if saved_changes['state_id'].blank?
  16. # check if existing online notifications for this ticket should be set to seen
  17. return true if !OnlineNotification.seen_state?(self)
  18. # set all online notifications to seen
  19. # send background job
  20. TicketOnlineNotificationSeenJob.perform_later(id, updated_by_id)
  21. end
  22. end