docbrown/app/workers/notifications/new_reaction_worker.rb
Emma Goto 34e5b68182
[deploy] Add ability to turn off reaction notifications in notification settings (#9435)
* Add ability to turn off reaction notifications in notification settings

* Rename article_reaction_notifications to react-Notifications

* Rename platform notification settings to general notification settings and add reactions toggle

* Fix new_reaction_worker_spec

Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Molly Struve <mollylbs@gmail.com>
2020-08-23 16:54:36 +02:00

26 lines
881 B
Ruby

module Notifications
class NewReactionWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority, retry: 10
def perform(reaction_data, receiver_data)
# Sidekiq Parameters are hash with stringified keys, so we need to symbolize keys
receiver_data = receiver_data.symbolize_keys
reaction_data = reaction_data.symbolize_keys
receiver_klass = receiver_data.fetch(:klass)
return unless %w[User Organization].include?(receiver_klass)
receiver = receiver_klass.constantize.find_by(id: receiver_data.fetch(:id))
Notifications::Reactions::Send.call(reaction_data, receiver) if should_send?(receiver, receiver_klass)
end
def should_send?(receiver, receiver_klass)
return false unless receiver
return true if receiver_klass == "Organization"
receiver.reaction_notifications
end
end
end