2018-05-02 23:10:57 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LocalNotificationWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2020-09-18 18:26:45 +03:00
|
|
|
def perform(receiver_account_id, activity_id = nil, activity_class_name = nil, type = nil)
|
2018-11-08 22:05:42 +02:00
|
|
|
if activity_id.nil? && activity_class_name.nil?
|
|
|
|
activity = Mention.find(receiver_account_id)
|
|
|
|
receiver = activity.account
|
|
|
|
else
|
|
|
|
receiver = Account.find(receiver_account_id)
|
|
|
|
activity = activity_class_name.constantize.find(activity_id)
|
|
|
|
end
|
|
|
|
|
2022-02-11 23:20:19 +02:00
|
|
|
# For most notification types, only one notification should exist, and the older one is
|
|
|
|
# preferred. For updates, such as when a status is edited, the new notification
|
|
|
|
# should replace the previous ones.
|
|
|
|
if type == 'update'
|
|
|
|
Notification.where(account: receiver, activity: activity, type: 'update').in_batches.delete_all
|
|
|
|
elsif Notification.where(account: receiver, activity: activity, type: type).any?
|
|
|
|
return
|
|
|
|
end
|
2022-01-19 23:37:27 +02:00
|
|
|
|
2020-09-18 18:26:45 +03:00
|
|
|
NotifyService.new.call(receiver, type || activity_class_name.underscore, activity)
|
2018-05-02 23:10:57 +03:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|