Move comment email subject line code into models

This commit is contained in:
Raphael Sofaer 2011-08-11 10:45:28 -07:00
parent ad5bd90b63
commit a2043671ce
6 changed files with 23 additions and 3 deletions

View file

@ -74,7 +74,7 @@ class Notifier < ActionMailer::Base
I18n.with_locale(@receiver.language) do I18n.with_locale(@receiver.language) do
mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>", mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>",
:to => "\"#{@receiver.name}\" <#{@receiver.email}>", :to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => "Re: #{post_message(@comment.parent, :length => TRUNCATION_LEN)}") :subject => "Re: #{comment_email_subject}")
end end
end end
@ -89,13 +89,16 @@ class Notifier < ActionMailer::Base
log_mail(recipient_id, sender_id, 'comment_on_post') log_mail(recipient_id, sender_id, 'comment_on_post')
I18n.with_locale(@receiver.language) do I18n.with_locale(@receiver.language) do
subject_message = post_message(@comment.parent, :length => TRUNCATION_LEN)
mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>", mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>",
:to => "\"#{@receiver.name}\" <#{@receiver.email}>", :to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => "Re: #{subject_message}") :subject => "Re: #{comment_email_subject}")
end end
end end
def comment_email_subject
truncate(@comment.parent.comment_email_subject, :length => TRUNCATION_LEN)
end
def private_message(recipient_id, sender_id, message_id) def private_message(recipient_id, sender_id, message_id)
@receiver = User.find_by_id(recipient_id) @receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_id) @sender = Person.find_by_id(sender_id)

View file

@ -53,5 +53,9 @@ class ActivityStreams::Photo < Post
# A better solution is needed. # A better solution is needed.
# @return [Boolean] true # @return [Boolean] true
def activity_streams?; true; end def activity_streams?; true; end
def comment_email_subject
I18n.t("photos.comment_email_subject", :name => author.name)
end
end end

View file

@ -117,6 +117,10 @@ class Post < ActiveRecord::Base
false false
end end
def comment_email_subject
I18n.t('notifier.a_post_you_shared')
end
# @return [Array<Comment>] # @return [Array<Comment>]
def last_three_comments def last_three_comments
self.comments.order('created_at DESC').limit(3).includes(:author => :profile).reverse self.comments.order('created_at DESC').limit(3).includes(:author => :profile).reverse

View file

@ -31,6 +31,9 @@ class Reshare < Post
end end
end end
def comment_email_subject
I18n.t('reshares.comment_email_subject', :resharer => author.name, :author => root.author.name)
end
private private
def after_parse def after_parse

View file

@ -132,6 +132,10 @@ class StatusMessage < Post
end end
end end
def comment_email_subject
formatted_message(:plain_text => true)
end
protected protected
def message_or_photos_present? def message_or_photos_present?

View file

@ -533,6 +533,7 @@ en:
new_profile_photo: new_profile_photo:
upload: "Upload a new profile photo!" upload: "Upload a new profile photo!"
or_select_one: "or select one from your already existing" or_select_one: "or select one from your already existing"
comment_email_subject: "%{name}'s photo"
posts: posts:
show: show:
@ -621,6 +622,7 @@ en:
deleted: "Original post deleted by author." deleted: "Original post deleted by author."
create: create:
failure: "There was an error resharing this post." failure: "There was an error resharing this post."
comment_email_subject: "%{resharer}'s reshare of %{author}'s post"
services: services:
index: index:
logged_in_as: "logged in as" logged_in_as: "logged in as"