forked from berserker/microblog
parent
5b0e8cc92b
commit
0b3e4fd5de
12 changed files with 1 additions and 214 deletions
@ -1,44 +0,0 @@ |
||||
%table.email-table{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.email-body |
||||
.email-container |
||||
%table.content-section{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.content-cell.darker.hero-with-button |
||||
.email-row |
||||
.col-6 |
||||
%table.column{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.column-cell.text-center.padded |
||||
%h1= t 'notification_mailer.digest.title' |
||||
%p.lead= t('notification_mailer.digest.body', since: l((@me.user_current_sign_in_at || @since).to_date, format: :short), instance: site_hostname) |
||||
%table.button{ align: 'center', cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.button-primary |
||||
= link_to web_url do |
||||
%span= t 'notification_mailer.digest.action' |
||||
|
||||
- @notifications.each_with_index do |n, i| |
||||
= render 'status', status: n.target_status, i: i |
||||
|
||||
- unless @follows_since.zero? |
||||
%table.email-table{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.email-body |
||||
.email-container |
||||
%table.content-section{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.content-cell.content-start.border-top |
||||
.email-row |
||||
.col-6 |
||||
%table.column{ cellspacing: 0, cellpadding: 0 } |
||||
%tbody |
||||
%tr |
||||
%td.column-cell.text-center |
||||
%p= t('notification_mailer.digest.new_followers_summary', count: @follows_since) |
@ -1,15 +0,0 @@ |
||||
<%= raw t('application_mailer.salutation', name: display_name(@me)) %> |
||||
|
||||
<%= raw t('notification_mailer.digest.body', since: l(@me.user_current_sign_in_at || @since), instance: root_url) %> |
||||
<% @notifications.each do |notification| %> |
||||
|
||||
* <%= raw t('notification_mailer.digest.mention', name: notification.from_account.pretty_acct) %> |
||||
|
||||
<%= raw extract_status_plain_text(notification.target_status) %> |
||||
|
||||
<%= raw t('application_mailer.view')%> <%= web_url("statuses/#{notification.target_status.id}") %> |
||||
<% end %> |
||||
<% if @follows_since > 0 %> |
||||
|
||||
<%= raw t('notification_mailer.digest.new_followers_summary', count: @follows_since) %> |
||||
<% end %> |
@ -1,21 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class DigestMailerWorker |
||||
include Sidekiq::Worker |
||||
|
||||
sidekiq_options queue: 'mailers' |
||||
|
||||
attr_reader :user |
||||
|
||||
def perform(user_id) |
||||
@user = User.find(user_id) |
||||
deliver_digest if @user.allows_digest_emails? |
||||
end |
||||
|
||||
private |
||||
|
||||
def deliver_digest |
||||
NotificationMailer.digest(user.account).deliver_now! |
||||
user.touch(:last_emailed_at) |
||||
end |
||||
end |
@ -1,25 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Scheduler::EmailScheduler |
||||
include Sidekiq::Worker |
||||
|
||||
sidekiq_options retry: 0 |
||||
|
||||
FREQUENCY = 7.days.freeze |
||||
SIGN_IN_OFFSET = 1.day.freeze |
||||
|
||||
def perform |
||||
eligible_users.reorder(nil).find_each do |user| |
||||
next unless user.allows_digest_emails? |
||||
DigestMailerWorker.perform_async(user.id) |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def eligible_users |
||||
User.emailable |
||||
.where('current_sign_in_at < ?', (FREQUENCY + SIGN_IN_OFFSET).ago) |
||||
.where('last_emailed_at IS NULL OR last_emailed_at < ?', FREQUENCY.ago) |
||||
end |
||||
end |
@ -1,36 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
require 'rails_helper' |
||||
|
||||
describe DigestMailerWorker do |
||||
describe 'perform' do |
||||
let(:user) { Fabricate(:user, last_emailed_at: 3.days.ago) } |
||||
|
||||
context 'for a user who receives digests' do |
||||
it 'sends the email' do |
||||
service = double(deliver_now!: nil) |
||||
allow(NotificationMailer).to receive(:digest).and_return(service) |
||||
update_user_digest_setting(true) |
||||
described_class.perform_async(user.id) |
||||
|
||||
expect(NotificationMailer).to have_received(:digest) |
||||
expect(user.reload.last_emailed_at).to be_within(1).of(Time.now.utc) |
||||
end |
||||
end |
||||
|
||||
context 'for a user who does not receive digests' do |
||||
it 'does not send the email' do |
||||
allow(NotificationMailer).to receive(:digest) |
||||
update_user_digest_setting(false) |
||||
described_class.perform_async(user.id) |
||||
|
||||
expect(NotificationMailer).not_to have_received(:digest) |
||||
expect(user.last_emailed_at).to be_within(1).of(3.days.ago) |
||||
end |
||||
end |
||||
|
||||
def update_user_digest_setting(value) |
||||
user.settings['notification_emails'] = user.settings['notification_emails'].merge('digest' => value) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue