Class: Bible270::NoticeMailer

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/bible270/notice_mailer.rb

Overview

Transactional mail for readers and notices for whoever runs the plan.

Instance Method Summary collapse

Instance Method Details

#broadcast(reader_id:, subject:, body:) ⇒ Object

A message from whoever runs the plan to one reader. Sent individually rather than as one email with everyone in bcc: a bcc list of a hundred addresses is a spam signal, and it means nobody can be greeted by name or unsubscribe meaningfully.



60
61
62
63
64
65
66
67
68
69
70
# File 'app/mailers/bible270/notice_mailer.rb', line 60

def broadcast(reader_id:, subject:, body:)
  @reader = Reader.find_by(id: reader_id)
  return message.perform_deliveries = false if @reader.nil? || @reader.email.blank?
  return message.perform_deliveries = false if subject.to_s.strip.empty? || body.to_s.strip.empty?

  @body = body.to_s
  @app_name = Bible270.config.app_name
  @plan_url = plan_url

  mail to: @reader.email, subject: subject.to_s.strip
end

#daily_reminder(reader_id:, day:, on: Bible270.today) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/mailers/bible270/notice_mailer.rb', line 39

def daily_reminder(reader_id:, day:, on: Bible270.today)
  @reader = Reader.find_by(id: reader_id)
  return message.perform_deliveries = false unless Bible270.config.daily_reminders?
  return message.perform_deliveries = false if @reader.nil? || !@reader.daily_reminders? || @reader.email.blank?

  @day = day.to_i
  @on = Plan.to_date(on)
  return message.perform_deliveries = false unless Plan.valid_day?(@day) && @on

  @readings = Plan.readings_for(@day).select { |_, reference| reference }
  @app_name = Bible270.config.app_name
  @day_url = day_url_for(@day)
  @profile_url = profile_url

  mail to: @reader.email, subject: "#{@app_name}: day #{@day} reading reminder"
end

#mentioned(comment_id:, reader_id:) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/mailers/bible270/notice_mailer.rb', line 21

def mentioned(comment_id:, reader_id:)
  return message.perform_deliveries = false unless prepare_comment_notice(comment_id, reader_id)

  @heading = "#{@author.display_name} mentioned you"
  @introduction = "#{@author.display_name} mentioned you in a reflection on day #{@comment.day}."
  @reason = 'You are getting this because you asked to be emailed about replies and mentions.'
  deliver_comment_notice("#{@app_name}: #{@author.display_name} mentioned you on day #{@comment.day}")
end

#new_reader(reader_id:, recipients:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/mailers/bible270/notice_mailer.rb', line 6

def new_reader(reader_id:, recipients:)
  @reader = Reader.find_by(id: reader_id)
  # Blanks dropped rather than trusting the caller: ['']  is not blank — a
  # one-element array never is — so it would otherwise have been sent to an
  # empty address, which fails at the SMTP server rather than here.
  addresses = Array(recipients).map { |address| address.to_s.strip }.reject(&:empty?)
  return message.perform_deliveries = false if @reader.nil? || addresses.empty?

  @app_name = Bible270.config.app_name
  @total = Reader.count
  @admin_url = admin_url_for(@reader)

  mail to: addresses, subject: "#{@app_name}: #{@reader.display_name} has joined"
end

#replied(comment_id:, reader_id:) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/mailers/bible270/notice_mailer.rb', line 30

def replied(comment_id:, reader_id:)
  return message.perform_deliveries = false unless prepare_comment_notice(comment_id, reader_id)

  @heading = "#{@author.display_name} replied to your reflection"
  @introduction = "#{@author.display_name} replied to your reflection on day #{@comment.day}."
  @reason = 'You are getting this because you asked to be emailed about replies and mentions.'
  deliver_comment_notice("#{@app_name}: #{@author.display_name} replied on day #{@comment.day}")
end