Sha256: e629ad0fbe58c1ed503674132e6a4495e93596fe09e5a6aea41ca312b535f858

Contents?: true

Size: 672 Bytes

Versions: 12

Compression:

Stored size: 672 Bytes

Contents

# frozen_string_literal: true

module Decidim
  class EmailNotificationsDigestGeneratorJob < ApplicationJob
    queue_as :mailers

    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: time)
      return unless should_notify

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

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.8 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.7 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.6 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.5 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.4 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.3 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.2 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.1 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.0 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.0.rc2 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.27.0.rc1 app/jobs/decidim/email_notifications_digest_generator_job.rb