Files
grecia/app/models/comment_notifier.rb
Amaia Castro c4265e76a3 Don’t send notifications when commenting on an annotation
First level comments are considered different threads, so no need to notify the first commenter about other threads
2017-01-20 18:46:57 +01:00

36 lines
819 B
Ruby

class CommentNotifier
def initialize(args = {})
@comment = args.fetch(:comment)
@author = @comment.author
end
def process
send_comment_email
send_reply_email
end
private
def send_comment_email
unless @comment.commentable.is_a?(Legislation::Annotation)
Mailer.comment(@comment).deliver_later if email_on_comment?
end
end
def send_reply_email
Mailer.reply(@comment).deliver_later if email_on_comment_reply?
end
def email_on_comment?
commentable_author = @comment.commentable.author
commentable_author != @author && commentable_author.email_on_comment?
end
def email_on_comment_reply?
return false unless @comment.reply?
parent_author = @comment.parent.author
parent_author != @author && parent_author.email_on_comment_reply?
end
end