Last active
August 29, 2015 13:57
-
-
Save marclove/9378655 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController | |
def create | |
comment = Comment.new(params[:comment]) | |
@comment = CommentCreator.new(comment).create! | |
respond_with @comment | |
end | |
end | |
class CommentCreator | |
def initialize(comment) | |
@comment = comment | |
@comment_thread = comment.comment_thread | |
end | |
def create! | |
@comment.save! | |
CommentCreatedWorker.perform_async(@comment.id) | |
@comment | |
end | |
def perform | |
comment_thread.participants.each do |participant| | |
CommentThreadMailer.activity_notification(comment_thread, comment, participant) | |
end | |
if comment.previous_comment? | |
in_reply_to_user = comment.previous_comment.author | |
ReplyMailer.notification(in_reply_to_user, comment).deliver | |
end | |
Kissmetrics.record(comment.author, 'Added Comment') | |
end | |
end | |
class CommentCreatedWorker | |
include Sidekiq::Worker | |
def perform(comment_id) | |
comment = Comment.find(comment_id) | |
CommentCreator.new(comment).perform | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment