mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Remove full quotes of direct replies. (#6729)
This commit is contained in:
committed by
Régis Hanol
parent
df3bb07ec6
commit
41e184280d
@@ -32,6 +32,7 @@ class CookedPostProcessor
|
||||
def post_process(bypass_bump = false)
|
||||
DistributedMutex.synchronize("post_process_#{@post.id}") do
|
||||
DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
|
||||
removed_direct_reply_full_quotes
|
||||
post_process_oneboxes
|
||||
post_process_images
|
||||
post_process_quotes
|
||||
@@ -85,6 +86,28 @@ class CookedPostProcessor
|
||||
end
|
||||
end
|
||||
|
||||
def removed_direct_reply_full_quotes
|
||||
return if @post.post_number == 1
|
||||
|
||||
num_quotes = @doc.css("aside.quote").size
|
||||
return if num_quotes != 1
|
||||
|
||||
prev = Post.where('post_number < ? AND topic_id = ? AND post_type = ? AND not hidden', @post.post_number, @post.topic_id, Post.types[:regular]).order('post_number desc').limit(1).pluck(:raw).first
|
||||
return if !prev
|
||||
|
||||
new_raw = @post.raw.gsub(/\[quote[^\]]*\]\s*#{Regexp.quote(prev.strip)}\s*\[\/quote\]/, '')
|
||||
return if @post.raw == new_raw
|
||||
|
||||
PostRevisor.new(@post).revise!(
|
||||
Discourse.system_user,
|
||||
{
|
||||
raw: new_raw.strip,
|
||||
edit_reason: I18n.t(:removed_direct_reply_full_quotes)
|
||||
},
|
||||
skip_validations: true
|
||||
)
|
||||
end
|
||||
|
||||
def add_image_placeholder!(img)
|
||||
src = img["src"].sub(/^https?:/i, "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user