Class: Decidim::EmailNotificationsDigestGeneratorJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/decidim/email_notifications_digest_generator_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(user_id, frequency, time: Time.now.utc, force: false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/decidim/email_notifications_digest_generator_job.rb', line 7

def perform(user_id, frequency, time: Time.now.utc, force: false)
  user = Decidim::User.find_by(id: user_id)
  return if user.blank?

  should_notify = force || NotificationsDigestSendingDecider.must_notify?(user, time)
  return unless should_notify

  notification_ids = user.notifications.try(frequency, time).pluck(:id)
  return if notification_ids.blank?

  NotificationsDigestMailer.digest_mail(user, notification_ids).deliver_later
  user.update(digest_sent_at: time)
end