A platform for community discussion. Free, open, simple.
FEATURE: Remove full quotes only from new posts. (#6862)
Bianca Nenciu7d84648d1162
diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rbindex 6c8b4e7d2f9..ef06ea52dc2 100644--- a/app/jobs/regular/process_post.rb+++ b/app/jobs/regular/process_post.rb@@ -21,7 +21,7 @@ module Jobsendcp = CookedPostProcessor.new(post, args)- cp.post_process(args[:bypass_bump])+ cp.post_process(bypass_bump: args[:bypass_bump], new_post: args[:new_post])# If we changed the document, save itcooked = cp.htmldiff --git a/app/models/post.rb b/app/models/post.rbindex 19d093d967b..329ed664edc 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -690,10 +690,11 @@ class Post < ActiveRecord::Baseend# Enqueue post processing for this post- def trigger_post_process(bypass_bump: false, priority: :normal)+ def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false)args = {post_id: id,bypass_bump: bypass_bump,+ new_post: new_post,}args[:image_sizes] = image_sizes if image_sizes.present?args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 9ab9ca6b157..01c639bf8a4 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -33,10 +33,10 @@ class CookedPostProcessor@disable_loading_image = !!opts[:disable_loading_image]end- def post_process(bypass_bump = false)+ def post_process(bypass_bump: false, new_post: false)DistributedMutex.synchronize("post_process_#{@post.id}") doDiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)- removed_direct_reply_full_quotes+ removed_direct_reply_full_quotes if new_postpost_process_oneboxespost_process_imagespost_process_quotesdiff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rbindex 4dde3b73afa..cbcd68623a8 100644--- a/lib/post_jobs_enqueuer.rb+++ b/lib/post_jobs_enqueuer.rb@@ -38,7 +38,7 @@ class PostJobsEnqueuerenddef trigger_post_post_process- @post.trigger_post_process+ @post.trigger_post_process(new_post: true)enddef after_post_creatediff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 9e2628a4c57..ebca1f0d2df 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -1170,7 +1170,7 @@ describe CookedPostProcessor dolet!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }let(:raw) do- <<~RAW+ <<~RAW.strip[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]this is the first post[/quote]@@ -1180,7 +1180,7 @@ describe CookedPostProcessor doendlet(:raw2) do- <<~RAW+ <<~RAW.stripand this is the third reply[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]@@ -1189,9 +1189,11 @@ describe CookedPostProcessor doRAWend- it 'works' do+ before doSiteSetting.remove_full_quote = true+ end+ it 'works' dohidden = 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)@@ -1210,8 +1212,6 @@ describe CookedPostProcessor doendit 'does not delete quote if not first paragraph' do- SiteSetting.remove_full_quote = true-reply = Fabricate(:post, topic: topic, raw: raw2)CookedPostProcessor.new(reply).removed_direct_reply_full_quotesexpect(topic.posts).to eq([post, reply])@@ -1227,6 +1227,20 @@ describe CookedPostProcessor doexpect(reply.raw).to eq(raw)end+ it "works only on new posts" do+ 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])+ Jobs.stubs(:enqueue) { |job, args| CookedPostProcessor.new(reply).post_process(new_post: args[:new_post]) if job == :process_post }++ reply = PostCreator.create!(topic.user, topic_id: topic.id, raw: raw)+ CookedPostProcessor.new(reply).post_process+ expect(reply.raw).to eq(raw)++ PostRevisor.new(reply).revise!(Discourse.system_user, raw: raw, edit_reason: "put back full quote")+ CookedPostProcessor.new(reply).post_process(new_post: true)+ expect(reply.raw).to eq("and this is the third reply")+ end+endend