2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-12-21 16:33:45 +00:00
|
|
|
class TicketOnlineNotificationSeenJob < ApplicationJob
|
2019-11-13 07:03:47 +00:00
|
|
|
include HasActiveJobLock
|
|
|
|
|
|
|
|
def lock_key
|
|
|
|
# "TicketOnlineNotificationSeenJob/23/42"
|
|
|
|
"#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
|
|
|
|
end
|
|
|
|
|
2018-12-21 16:33:45 +00:00
|
|
|
def perform(ticket_id, user_id)
|
2021-07-16 14:10:31 +00:00
|
|
|
user_id ||= 1
|
2018-12-21 16:33:45 +00:00
|
|
|
|
|
|
|
# set all online notifications to seen
|
|
|
|
Transaction.execute do
|
|
|
|
ticket = Ticket.lookup(id: ticket_id)
|
|
|
|
OnlineNotification.list_by_object('Ticket', ticket_id).each do |notification|
|
|
|
|
next if notification.seen
|
|
|
|
|
|
|
|
seen = ticket.online_notification_seen_state(notification.user_id)
|
|
|
|
next if !seen
|
|
|
|
next if seen == notification.seen
|
|
|
|
|
|
|
|
notification.seen = true
|
|
|
|
notification.updated_by_id = user_id
|
|
|
|
notification.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|