mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: user got notified about a mention inside a chat message quote (#24229)
When quoting a chat message in a post, if that message contains a mention,
that mention should be ignored. But we've been detecting them and sending
notifications to users. This PR fixes the problem. Since this fix is for
the chat plugin, I had to introduce a new API for plugins:
# We strip posts before detecting mentions, oneboxes, attachments etc.
# We strip those elements that shouldn't be detected. For example,
# a mention inside a quote should be ignored, so we strip it off.
# Using this API plugins can register their own post strippers.
def register_post_stripper(&block)
end
This commit is contained in:
committed by
GitHub
parent
179abfca1a
commit
be2eb3df44
@@ -146,11 +146,9 @@ class PostAnalyzer
|
||||
def cooked_stripped
|
||||
@cooked_stripped ||=
|
||||
begin
|
||||
doc = Nokogiri::HTML5.fragment(cook(@raw, topic_id: @topic_id))
|
||||
doc.css(
|
||||
"pre .mention, aside.quote > .title, aside.quote .mention, aside.quote .mention-group, .onebox, .elided",
|
||||
).remove
|
||||
doc
|
||||
cooked = cook(@raw, topic_id: @topic_id)
|
||||
fragment = Nokogiri::HTML5.fragment(cooked)
|
||||
PostStripper.strip(fragment)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
28
app/models/post_stripper.rb
Normal file
28
app/models/post_stripper.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# We strip posts before detecting mentions, oneboxes, attachments etc.
|
||||
# We strip those elements that shouldn't be detected. For example,
|
||||
# a mention inside a quote should be ignored, so we strip it off.
|
||||
class PostStripper
|
||||
def self.strip(nokogiri_fragment)
|
||||
run_core_strippers(nokogiri_fragment)
|
||||
run_plugin_strippers(nokogiri_fragment)
|
||||
nokogiri_fragment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.run_core_strippers(nokogiri_fragment)
|
||||
nokogiri_fragment.css(
|
||||
"pre .mention, aside.quote > .title, aside.quote .mention, aside.quote .mention-group, .onebox, .elided",
|
||||
).remove
|
||||
end
|
||||
|
||||
def self.run_plugin_strippers(nokogiri_fragment)
|
||||
DiscoursePluginRegistry.post_strippers.each do |stripper|
|
||||
stripper[:block].call(nokogiri_fragment)
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method :run_core_strippers, :run_plugin_strippers
|
||||
end
|
||||
Reference in New Issue
Block a user