2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-14 01:07:51 +08:00
|
|
|
class QuoteComparer
|
|
|
|
def self.whitespace
|
2020-04-30 14:48:34 +08:00
|
|
|
" \t\r\n"
|
2018-03-14 01:07:51 +08:00
|
|
|
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"
|
2022-05-12 23:07:43 +08:00
|
|
|
def missing?
|
2023-08-10 08:03:38 +08:00
|
|
|
@parent_post.blank?
|
2022-05-12 23:07:43 +08:00
|
|
|
end
|
|
|
|
|
2018-03-14 01:07:51 +08:00
|
|
|
def modified?
|
2022-05-12 23:07:43 +08:00
|
|
|
return true if @text.blank?
|
2018-03-14 01:07:51 +08:00
|
|
|
|
2022-05-12 23:07:43 +08:00
|
|
|
if @parent_post
|
|
|
|
parent_text =
|
|
|
|
Nokogiri::HTML5.fragment(@parent_post.cooked).text.delete(QuoteComparer.whitespace)
|
|
|
|
text = @text.delete(QuoteComparer.whitespace)
|
2018-03-14 01:07:51 +08:00
|
|
|
|
2022-05-12 23:07:43 +08:00
|
|
|
!parent_text.include?(text)
|
|
|
|
end
|
2018-03-14 01:07:51 +08:00
|
|
|
end
|
|
|
|
end
|