prevents users to receive email notifications about own comments and replies
This commit is contained in:
@@ -7,10 +7,7 @@ class CommentsController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def create
|
||||
if @comment.save
|
||||
Mailer.comment(@comment).deliver_later if email_on_debate_comment?
|
||||
Mailer.reply(@comment).deliver_later if email_on_comment_reply?
|
||||
else
|
||||
unless @comment.save
|
||||
render :new
|
||||
end
|
||||
end
|
||||
@@ -55,14 +52,6 @@ class CommentsController < ApplicationController
|
||||
@commentable = Comment.find_commentable(comment_params[:commentable_type], comment_params[:commentable_id])
|
||||
end
|
||||
|
||||
def email_on_debate_comment?
|
||||
@comment.commentable.author.email_on_debate_comment?
|
||||
end
|
||||
|
||||
def email_on_comment_reply?
|
||||
@comment.reply? && @comment.parent.author.email_on_comment_reply?
|
||||
end
|
||||
|
||||
def administrator_comment?
|
||||
["1", true].include?(comment_params[:as_administrator]) && can?(:comment_as_administrator, Debate)
|
||||
end
|
||||
|
||||
33
app/models/comment_notifier.rb
Normal file
33
app/models/comment_notifier.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
Mailer.comment(@comment).deliver_later if email_on_debate_comment?
|
||||
end
|
||||
|
||||
def send_reply_email
|
||||
Mailer.reply(@comment).deliver_later if email_on_comment_reply?
|
||||
end
|
||||
|
||||
def email_on_debate_comment?
|
||||
commentable_author = @comment.commentable.author
|
||||
commentable_author != @author && commentable_author.email_on_debate_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
|
||||
Reference in New Issue
Block a user