move comment thread_id generation to Comment

This commit is contained in:
joshua stein 2013-06-25 13:55:40 -05:00
parent 7ff7b676e5
commit ed512cc065
2 changed files with 12 additions and 5 deletions

View file

@ -21,14 +21,12 @@ class CommentsController < ApplicationController
if pc = Comment.find_by_story_id_and_short_id(story.id, if pc = Comment.find_by_story_id_and_short_id(story.id,
params[:parent_comment_short_id]) params[:parent_comment_short_id])
comment.parent_comment_id = pc.id comment.parent_comment_id = pc.id
comment.parent_comment_short_id = pc.short_id # needed for carryng along in comment preview form
comment.thread_id = pc.thread_id comment.parent_comment_short_id = params[:parent_comment_short_id]
else else
return render :json => { :error => "invalid parent comment", return render :json => { :error => "invalid parent comment",
:status => 400 } :status => 400 }
end end
else
comment.thread_id = Keystore.incremented_value_for("thread_id")
end end
# prevent double-clicks of the post button # prevent double-clicks of the post button

View file

@ -13,7 +13,8 @@ class Comment < ActiveRecord::Base
attr_accessor :parent_comment_short_id, :current_vote, :previewing, attr_accessor :parent_comment_short_id, :current_vote, :previewing,
:indent_level, :highlighted :indent_level, :highlighted
before_create :assign_short_id_and_upvote, :assign_initial_confidence before_create :assign_short_id_and_upvote, :assign_initial_confidence,
:assign_thread_id
after_create :assign_votes, :mark_submitter, :deliver_reply_notifications, after_create :assign_votes, :mark_submitter, :deliver_reply_notifications,
:deliver_mention_notifications :deliver_mention_notifications
after_destroy :unassign_votes after_destroy :unassign_votes
@ -254,6 +255,14 @@ class Comment < ActiveRecord::Base
self.confidence = self.calculated_confidence self.confidence = self.calculated_confidence
end end
def assign_thread_id
if self.parent_comment_id.present?
self.thread_id = self.parent_comment.thread_id
else
self.thread_id = Keystore.incremented_value_for("thread_id")
end
end
def unassign_votes def unassign_votes
self.story.update_comment_count! self.story.update_comment_count!
end end