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)
|
|
|
|
user_id = user_id || 1
|
|
|
|
|
|
|
|
# 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
|