mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
feffe23cc5
* Rearrange frontend to account for mailing list mode * Allow update of user preference for mailing list frequency * Add mailing list frequency estimate * Simplify frequency estimate; disable activity summary for mailing list mode * Remove combined updates * Add specs for enqueue mailing list mode job * Write mailing list method for mailer * Fix linting error * Account for stale topics * Add translations for default mailing list setting * One query for mailing list topics * Fix failing spec * WIP * Flesh out html template * First pass at text-based mailing list summary * Add user avatar * Properly format posts for mailing list * Move make_all_links_absolute into Email::Styles * Apply first_seen_at to user * Send mailing list email summary hourly based on first_seen_at * Branch and test cleanup * Use existing mailing list mode estimate * Fix failing specs
27 lines
1 KiB
Ruby
27 lines
1 KiB
Ruby
module Jobs
|
|
|
|
class EnqueueMailingListEmails < Jobs::Scheduled
|
|
every 1.hour
|
|
|
|
def execute(args)
|
|
return if SiteSetting.disable_mailing_list_mode?
|
|
target_user_ids.each do |user_id|
|
|
Jobs.enqueue(:user_email, type: :mailing_list, user_id: user_id)
|
|
end
|
|
end
|
|
|
|
def target_user_ids
|
|
# Users who want to receive daily mailing list emails
|
|
User.real
|
|
.not_suspended
|
|
.joins(:user_option)
|
|
.where(active: true, staged: false, user_options: {mailing_list_mode: true, mailing_list_mode_frequency: 0})
|
|
.where("#{!SiteSetting.must_approve_users?} OR approved OR moderator OR admin")
|
|
.where("date_part('hour', first_seen_at) = date_part('hour', CURRENT_TIMESTAMP)") # where the hour of first_seen_at is the same as the current hour
|
|
.where("COALESCE(first_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - '23 HOURS'::INTERVAL") # don't send unless you've been around for a day already
|
|
.pluck(:id)
|
|
end
|
|
|
|
end
|
|
|
|
end
|