diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 076eedc..a7f3bf6 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -21,14 +21,12 @@ class CommentsController < ApplicationController if pc = Comment.find_by_story_id_and_short_id(story.id, params[:parent_comment_short_id]) comment.parent_comment_id = pc.id - comment.parent_comment_short_id = pc.short_id - comment.thread_id = pc.thread_id + # needed for carryng along in comment preview form + comment.parent_comment_short_id = params[:parent_comment_short_id] else return render :json => { :error => "invalid parent comment", :status => 400 } end - else - comment.thread_id = Keystore.incremented_value_for("thread_id") end # prevent double-clicks of the post button diff --git a/app/models/comment.rb b/app/models/comment.rb index 20d1312..13703c7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -13,7 +13,8 @@ class Comment < ActiveRecord::Base attr_accessor :parent_comment_short_id, :current_vote, :previewing, :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, :deliver_mention_notifications after_destroy :unassign_votes @@ -254,6 +255,14 @@ class Comment < ActiveRecord::Base self.confidence = self.calculated_confidence 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 self.story.update_comment_count! end