-
-
Save fbuys/b9897096a5863ff754dce9457054edcd to your computer and use it in GitHub Desktop.
Threaded emails: Final result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotificationMailer < ApplicationMailer | |
def review_notification(recipient, review) | |
@review = review | |
@recipient = recipient | |
mail_settings = { | |
to: "#{recipient.name} <#{recipient.email}>", | |
subject: "Review: #{review.book.title}" | |
}.merge(headers(review)) | |
mail(mail_settings) | |
end | |
private | |
def headers(review) | |
{ | |
in_reply_to: thread_id(review), | |
references: thread_id(review) | |
}.reject { |_, v| v.blank? } | |
end | |
def message_id(review) | |
return "" if review.nil? | |
"<notification-#{review.id}-#{review.created_at.to_i}@#{ENV["domain"]}>" | |
end | |
def reviews_in_thread(review) | |
Review.where.not(id: review.id).where("book_id", review.book_id).order(:created_at) | |
end | |
def thread_id(review) | |
first_review = reviews_in_thread(review).first | |
message_id(first_review) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment