mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Remove full quotes only from new posts. (#6862)
This commit is contained in:
parent
e7d2a0d42f
commit
7d84648d11
@ -21,7 +21,7 @@ module Jobs
|
|||||||
end
|
end
|
||||||
|
|
||||||
cp = CookedPostProcessor.new(post, args)
|
cp = 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 it
|
# If we changed the document, save it
|
||||||
cooked = cp.html
|
cooked = cp.html
|
||||||
|
@ -690,10 +690,11 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Enqueue post processing for this post
|
# 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 = {
|
args = {
|
||||||
post_id: id,
|
post_id: id,
|
||||||
bypass_bump: bypass_bump,
|
bypass_bump: bypass_bump,
|
||||||
|
new_post: new_post,
|
||||||
}
|
}
|
||||||
args[:image_sizes] = image_sizes if image_sizes.present?
|
args[:image_sizes] = image_sizes if image_sizes.present?
|
||||||
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
||||||
|
@ -33,10 +33,10 @@ class CookedPostProcessor
|
|||||||
@disable_loading_image = !!opts[:disable_loading_image]
|
@disable_loading_image = !!opts[:disable_loading_image]
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_process(bypass_bump = false)
|
def post_process(bypass_bump: false, new_post: false)
|
||||||
DistributedMutex.synchronize("post_process_#{@post.id}") do
|
DistributedMutex.synchronize("post_process_#{@post.id}") do
|
||||||
DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
|
DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
|
||||||
removed_direct_reply_full_quotes
|
removed_direct_reply_full_quotes if new_post
|
||||||
post_process_oneboxes
|
post_process_oneboxes
|
||||||
post_process_images
|
post_process_images
|
||||||
post_process_quotes
|
post_process_quotes
|
||||||
|
@ -38,7 +38,7 @@ class PostJobsEnqueuer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def trigger_post_post_process
|
def trigger_post_post_process
|
||||||
@post.trigger_post_process
|
@post.trigger_post_process(new_post: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_post_create
|
def after_post_create
|
||||||
|
@ -1170,7 +1170,7 @@ describe CookedPostProcessor do
|
|||||||
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
|
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
|
||||||
|
|
||||||
let(:raw) do
|
let(:raw) do
|
||||||
<<~RAW
|
<<~RAW.strip
|
||||||
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
|
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
|
||||||
this is the first post
|
this is the first post
|
||||||
[/quote]
|
[/quote]
|
||||||
@ -1180,7 +1180,7 @@ describe CookedPostProcessor do
|
|||||||
end
|
end
|
||||||
|
|
||||||
let(:raw2) do
|
let(:raw2) do
|
||||||
<<~RAW
|
<<~RAW.strip
|
||||||
and this is the third reply
|
and this is the third reply
|
||||||
|
|
||||||
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
|
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
|
||||||
@ -1189,9 +1189,11 @@ describe CookedPostProcessor do
|
|||||||
RAW
|
RAW
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'works' do
|
before do
|
||||||
SiteSetting.remove_full_quote = true
|
SiteSetting.remove_full_quote = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'works' do
|
||||||
hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
|
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])
|
small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
|
||||||
reply = Fabricate(:post, topic: topic, raw: raw)
|
reply = Fabricate(:post, topic: topic, raw: raw)
|
||||||
@ -1210,8 +1212,6 @@ describe CookedPostProcessor do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'does not delete quote if not first paragraph' do
|
it 'does not delete quote if not first paragraph' do
|
||||||
SiteSetting.remove_full_quote = true
|
|
||||||
|
|
||||||
reply = Fabricate(:post, topic: topic, raw: raw2)
|
reply = Fabricate(:post, topic: topic, raw: raw2)
|
||||||
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
|
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
|
||||||
expect(topic.posts).to eq([post, reply])
|
expect(topic.posts).to eq([post, reply])
|
||||||
@ -1227,6 +1227,20 @@ describe CookedPostProcessor do
|
|||||||
expect(reply.raw).to eq(raw)
|
expect(reply.raw).to eq(raw)
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user