From e9a1af0113b6e6790c59b4586da79cc9b87651d6 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 31 Jul 2014 11:38:03 +1000 Subject: [PATCH] FIX: Do not suppress reply-to when other posts quoted --- app/models/post.rb | 4 ---- app/models/quoted_post.rb | 12 ++++++++++++ app/serializers/post_serializer.rb | 2 +- config/locales/server.en.yml | 2 +- .../20140731011328_add_reply_quoted_to_posts.rb | 16 ++++++++++++++++ spec/models/post_spec.rb | 4 ---- spec/models/quoted_post_spec.rb | 5 ++++- 7 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20140731011328_add_reply_quoted_to_posts.rb diff --git a/app/models/post.rb b/app/models/post.rb index 6f8389d9f24..04fd11e7293 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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) diff --git a/app/models/quoted_post.rb b/app/models/quoted_post.rb index 39e06d45f4f..e23456aebcb 100644 --- a/app/models/quoted_post.rb +++ b/app/models/quoted_post.rb @@ -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 diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index ce42fe36627..bff9c3fa650 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -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? diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 73a09f5d100..19397d61b21 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/db/migrate/20140731011328_add_reply_quoted_to_posts.rb b/db/migrate/20140731011328_add_reply_quoted_to_posts.rb new file mode 100644 index 00000000000..8dc7a8d4461 --- /dev/null +++ b/db/migrate/20140731011328_add_reply_quoted_to_posts.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 7c0ff726d2d..12402e3bcd8 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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 diff --git a/spec/models/quoted_post_spec.rb b/spec/models/quoted_post_spec.rb index 8943e0f758e..11f168d460f 100644 --- a/spec/models/quoted_post_spec.rb +++ b/spec/models/quoted_post_spec.rb @@ -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