FIX: Do not suppress reply-to when other posts quoted

This commit is contained in:
Sam 2014-07-31 11:38:03 +10:00
parent 9950c5bcd6
commit e9a1af0113
7 changed files with 34 additions and 11 deletions

View File

@ -252,10 +252,6 @@ class Post < ActiveRecord::Base
"#{topic_id}/#{post_number}"
end
def quoteless?
(quote_count == 0) && (reply_to_post_number.present?)
end
def reply_to_post
return if reply_to_post_number.blank?
@reply_to_post ||= Post.find_by("topic_id = :topic_id AND post_number = :post_number", topic_id: topic_id, post_number: reply_to_post_number)

View File

@ -44,6 +44,18 @@ class QuotedPost < ActiveRecord::Base
post_id: post.id, ids: ids
end
# simplest place to add this code
reply_quoted = false
if post.reply_to_post_number
reply_post_id = Post.where(topic_id: post.topic_id, post_number: post.reply_to_post_number).pluck(:id).first
reply_quoted = !!(reply_post_id && ids.include?(reply_post_id))
end
if reply_quoted != post.reply_quoted
post.update_columns(reply_quoted: reply_quoted)
end
end
end

View File

@ -206,7 +206,7 @@ class PostSerializer < BasicPostSerializer
end
def include_reply_to_user?
(!SiteSetting.suppress_reply_when_quoting || object.quoteless?) && object.reply_to_user
!(SiteSetting.suppress_reply_when_quoting && object.reply_quoted?) && object.reply_to_user
end
def include_bookmarked?

View File

@ -727,7 +727,7 @@ en:
send_welcome_message: "Send all new users a welcome private message with a quick start guide."
suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post."
suppress_reply_directly_above: "Don't show the expandable in-reply-to on a post when there is only a single reply directly above this post."
suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post contains any quotes."
suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply."
topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary."
topics_per_period_in_top_page: "Number of top topics shown on the expanded 'Show More' top topics."

View File

@ -0,0 +1,16 @@
class AddReplyQuotedToPosts < ActiveRecord::Migration
def up
add_column :posts, :reply_quoted, :boolean, null: false, default: false
execute "UPDATE posts p
SET reply_quoted = true
WHERE EXISTS(
SELECT 1 FROM quoted_posts q
JOIN posts p1 ON p1.post_number = p.reply_to_post_number AND p1.topic_id = p.topic_id
WHERE q.post_id = p.id AND q.quoted_post_id = p1.id
) AND p.reply_to_post_number IS NOT NULL"
end
def down
remove_column :posts, :reply_quoted
end
end

View File

@ -636,10 +636,6 @@ describe Post do
reply.quote_count.should == 1
end
it "isn't quoteless" do
reply.should_not be_quoteless
end
it 'has a reply to the user of the original user' do
reply.reply_to_user.should == post.user
end

View File

@ -4,9 +4,11 @@ describe QuotedPost do
it 'correctly extracts quotes in integration test' do
post1 = create_post
post2 = create_post(topic_id: post1.topic_id,
raw: "[quote=\"#{post1.user.username}, post: 1, topic:#{post1.topic_id}\"]\ntest\n[/quote]\nthis is a test post")
raw: "[quote=\"#{post1.user.username}, post: 1, topic:#{post1.topic_id}\"]\ntest\n[/quote]\nthis is a test post",
reply_to_post_number: 1)
QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id).should_not be_nil
post2.reply_quoted.should == true
end
it 'correctly handles deltas' do
@ -23,5 +25,6 @@ HTML
QuotedPost.where(post_id: post2.id).count.should == 1
QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id).should_not be_nil
post2.reply_quoted.should == false
end
end