mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 00:13:45 +08:00
20740f196c
Gracefully handle quotes from an external discourse instance by stripping quote-controls and including username in the title
33 lines
804 B
Ruby
33 lines
804 B
Ruby
# frozen_string_literal: true
|
|
|
|
class QuoteComparer
|
|
def self.whitespace
|
|
" \t\r\n"
|
|
end
|
|
|
|
def initialize(topic_id, post_number, text)
|
|
@topic_id = topic_id
|
|
@post_number = post_number
|
|
@text = text
|
|
@parent_post = Post.where(topic_id: @topic_id, post_number: @post_number).first
|
|
end
|
|
|
|
# This algorithm is far from perfect, but it follows the Discourse
|
|
# philosophy of "catch the obvious cases, leave moderation for the
|
|
# complicated ones"
|
|
def missing?
|
|
return true if @parent_post.blank?
|
|
end
|
|
|
|
def modified?
|
|
return true if @text.blank?
|
|
|
|
if @parent_post
|
|
parent_text = Nokogiri::HTML5::fragment(@parent_post.cooked).text.delete(QuoteComparer.whitespace)
|
|
text = @text.delete(QuoteComparer.whitespace)
|
|
|
|
!parent_text.include?(text)
|
|
end
|
|
end
|
|
end
|