cirandas.net

ref: master

app/mailers/comment_notifier.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class CommentNotifier < ApplicationMailer

  def notification(comment)
    profile = comment.article.profile
    self.environment = profile.environment
    @recipient = profile.nickname || profile.name
    @sender = comment.author_name
    @sender_link = comment.author_link
    @article_title = comment.article.name
    @comment_url = comment.url
    @comment_title = comment.title
    @comment_body = comment.body
    @url = profile.environment.top_url

    mail(
      to: comment.notification_emails,
      from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
      subject: _("[%s] you got a new comment!") % [profile.environment.name]
    )
  end

  def mail_to_followers(comment, emails)
    profile = comment.article.profile
    self.environment = profile.environment

    @recipient = profile.nickname || profile.name
    @sender = comment.author_name
    @sender_link = comment.author_link
    @article_title = comment.article.name
    @comment_url = comment.url
    @unsubscribe_url = comment.article.view_url.merge({:unfollow => true})
    @comment_title = comment.title
    @comment_body = comment.body
    @url = profile.environment.top_url

    mail(
      bcc: emails,
      from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
      subject: _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name]
    )
  end
end