FIX: filters ignore media descriptions (#13837)
* FIX: filters ignore media descriptions * remove parentheses to make codeclimate happy * combine the text and run the regular expression only once. https://github.com/tootsuite/mastodon/pull/13837#discussion_r431752581 * Fix use of “filter” instead of “compact”, fix coding style issues Co-authored-by: Thibaut Girka <thib@sitedethib.com>main
parent
5e6ec229b2
commit
c66403b257
|
@ -12,7 +12,7 @@ const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
|
||||||
|
|
||||||
export function searchTextFromRawStatus (status) {
|
export function searchTextFromRawStatus (status) {
|
||||||
const spoilerText = status.spoiler_text || '';
|
const spoilerText = status.spoiler_text || '';
|
||||||
const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
|
const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).concat(status.media_attachments.map(att => att.description)).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
|
||||||
return domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
|
return domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,9 +246,14 @@ class FeedManager
|
||||||
combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
|
combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
|
||||||
status = status.reblog if status.reblog?
|
status = status.reblog if status.reblog?
|
||||||
|
|
||||||
!combined_regex.match(Formatter.instance.plaintext(status)).nil? ||
|
combined_text = [
|
||||||
(status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?) ||
|
Formatter.instance.plaintext(status),
|
||||||
(status.preloadable_poll && !combined_regex.match(status.preloadable_poll.options.join("\n\n")).nil?)
|
status.spoiler_text,
|
||||||
|
status.preloadable_poll ? status.preloadable_poll.options.join("\n\n") : nil,
|
||||||
|
status.media_attachments.map(&:description).join("\n\n"),
|
||||||
|
].compact.join("\n\n")
|
||||||
|
|
||||||
|
!combined_regex.match(combined_text).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a status to an account's feed, returning true if a status was
|
# Adds a status to an account's feed, returning true if a status was
|
||||||
|
|
Loading…
Reference in New Issue