add info mail for new blog comments

This commit is contained in:
jomo
2014-05-03 03:33:09 +02:00
parent 4130216e11
commit e0b1540593
6 changed files with 51 additions and 33 deletions

View File

@@ -1,5 +1,7 @@
class Comment < ActiveRecord::Base
include MailerHelper
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
@@ -25,4 +27,33 @@ class Comment < ActiveRecord::Base
def edited?
!!user_editor_id
end
def send_new_comment_mail
userids = []
# thread + replies
posts = blogpost.comments.to_a
posts << blogpost # if thread.author.send_own_post_comment_mail (TODO)
posts.each do |post|
# don't send mail to the author, don't send to banned/disabled users
if post.author != author && post.author.normal? && post.author.confirmed? # &&
userids << post.author.id # && post.author.send_commented_comment_mail (TODO)
end
end
# making sure we don't send multiple mails to the same user
userids.uniq!
mails = []
userids.each do |uid|
begin
mails << RedstonerMailer.new_post_comment_mail(User.find(uid), self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create thread_reply mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"
Rails.logger.error e.message
Rails.logger.error "---"
end
end
background_mailer(mails)
end
end

View File

@@ -50,7 +50,7 @@ class Threadreply < ActiveRecord::Base
mails = []
userids.each do |uid|
begin
mails << RedstonerMailer.thread_reply_mail(User.find(uid), self)
mails << RedstonerMailer.new_thread_reply_mail(User.find(uid), self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create thread_reply mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"