Skip to content

A platform for community discussion. Free, open, simple.

* FEATURE: Adds site setting to let quotes on direct replies.

Bianca Nenciu7cac04e1a889
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 53dbf4945ad..44ea490a80c 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1308,6 +1308,7 @@ en:
send_tl1_welcome_message: "Send new trust level 1 users a welcome message."
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."
+ remove_full_quote: "Automatically remove full quotes on direct replies."
suppress_reply_when_quoting: "Don't show the expandable in-reply-to on a post when post quotes reply."
max_reply_history: "Maximum number of replies to expand when expanding in-reply-to"
topics_per_period_in_top_summary: "Number of top topics shown in the default top topics summary."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 9fb257110db..ebb1930f097 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -675,6 +675,8 @@ posting:
default: true
suppress_reply_when_quoting:
default: true
+ remove_full_quote:
+ default: true
max_reply_history:
default: 1
client: true
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 301ce313553..9c9ed222bbc 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -87,7 +87,7 @@ class CookedPostProcessor
end
def removed_direct_reply_full_quotes
- return if @post.post_number == 1
+ return if !SiteSetting.remove_full_quote || @post.post_number == 1
num_quotes = @doc.css("aside.quote").size
return if num_quotes != 1
@@ -104,7 +104,8 @@ class CookedPostProcessor
raw: new_raw.strip,
edit_reason: I18n.t(:removed_direct_reply_full_quotes)
},
- skip_validations: true
+ skip_validations: true,
+ bypass_bump: true
)
end
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 7decf8cfb82..829a4e8501e 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1146,28 +1146,44 @@ describe CookedPostProcessor do
context "remove direct reply full quote" do
let(:topic) { Fabricate(:topic) }
+ let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
+ let(:raw) do
+ <<~RAW
+ [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
+ this is the first post
+ [/quote]
+
+ and this is the third reply
+ RAW
+ end
it 'works' do
- post = Fabricate(:post, topic: topic, raw: "this is the first post")
- hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post")
- small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
- raw = <<~RAW
- [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
- this is the first post
- [/quote]
+ SiteSetting.remove_full_quote = true
- and this is the third reply
- RAW
+ hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
+ small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
reply = Fabricate(:post, topic: topic, raw: raw)
- cpp = CookedPostProcessor.new(reply)
- cpp.removed_direct_reply_full_quotes
+ freeze_time Time.zone.now do
+ topic.bumped_at = 1.day.ago
+ CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
+
+ expect(topic.posts).to eq([post, hidden, small_action, reply])
+ expect(topic.bumped_at).to eq(1.day.ago)
+ expect(reply.raw).to eq("and this is the third reply")
+ expect(reply.revisions.count).to eq(1)
+ expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])
+ expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes))
+ end
+ end
+
+ it "does nothing when 'remove_full_quote' is disabled" do
+ SiteSetting.remove_full_quote = false
+
+ reply = Fabricate(:post, topic: topic, raw: raw)
- expect(topic.posts).to eq([post, hidden, small_action, reply])
- expect(reply.raw).to eq("and this is the third reply")
- expect(reply.revisions.count).to eq(1)
- expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])
- expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes))
+ CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
+ expect(reply.raw).to eq(raw)
end
end