Sha256: e5bcd6416cf6e5b2543fd29b20f3f8db157ec072af70a84f848e2c1321a0abd5

Contents?: true

Size: 662 Bytes

Versions: 7

Compression:

Stored size: 662 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:)
      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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.3 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.2 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.1 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.0 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.0.rc5 app/jobs/decidim/email_notifications_digest_generator_job.rb
decidim-core-0.28.0.rc4 app/jobs/decidim/email_notifications_digest_generator_job.rb