mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
* Add yearly digest * Rename YearlyDigests to Users::Digests * Minor changes * Update yearly digest layout and styles * Add flags and chart to email * Update colors * Fix layout of stats in yearly digest view * Remove cron job for yearly digest scheduling * Update CHANGELOG.md * Update digest email setting handling * Allow sharing digest for 1 week or 1 month * Change Digests Distance to Bigint * Fix settings page
31 lines
812 B
Ruby
31 lines
812 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Users::Digests::EmailSendingJob < ApplicationJob
|
|
queue_as :mailers
|
|
|
|
def perform(user_id, year)
|
|
user = User.find(user_id)
|
|
digest = user.digests.yearly.find_by(year: year)
|
|
|
|
return unless should_send_email?(user, digest)
|
|
|
|
Users::DigestsMailer.with(user: user, digest: digest).year_end_digest.deliver_later
|
|
|
|
digest.update!(sent_at: Time.current)
|
|
rescue ActiveRecord::RecordNotFound
|
|
ExceptionReporter.call(
|
|
'Users::Digests::EmailSendingJob',
|
|
"User with ID #{user_id} not found. Skipping year-end digest email."
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def should_send_email?(user, digest)
|
|
return false unless user.safe_settings.digest_emails_enabled?
|
|
return false if digest.blank?
|
|
return false if digest.sent_at.present?
|
|
|
|
true
|
|
end
|
|
end
|