ticket_online_notification_seen_job.rb 845 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TicketOnlineNotificationSeenJob < ApplicationJob
  3. include HasActiveJobLock
  4. def lock_key
  5. # "TicketOnlineNotificationSeenJob/23/42"
  6. "#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
  7. end
  8. def perform(ticket_id, user_id)
  9. user_id ||= 1
  10. # set all online notifications to seen
  11. Transaction.execute do
  12. ticket = Ticket.lookup(id: ticket_id)
  13. OnlineNotification.list_by_object('Ticket', ticket_id).each do |notification|
  14. next if notification.seen
  15. seen = OnlineNotification.seen_state?(ticket, notification.user_id)
  16. next if !seen
  17. next if seen == notification.seen
  18. notification.seen = true
  19. notification.updated_by_id = user_id
  20. notification.save!
  21. end
  22. end
  23. end
  24. end