You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
828 B
32 lines
828 B
7 years ago
|
require 'htmlentities'
|
||
|
|
||
7 years ago
|
class Glitch::KeywordMuteHelper
|
||
7 years ago
|
include ActionView::Helpers::SanitizeHelper
|
||
|
|
||
|
attr_reader :text_matcher
|
||
|
attr_reader :tag_matcher
|
||
7 years ago
|
attr_reader :entity_decoder
|
||
7 years ago
|
|
||
|
def initialize(receiver_id)
|
||
7 years ago
|
@text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
|
||
|
@tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
|
||
|
@entity_decoder = HTMLEntities.new
|
||
7 years ago
|
end
|
||
|
|
||
|
def matches?(status)
|
||
|
matchers_match?(status) || (status.reblog? && matchers_match?(status.reblog))
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def matchers_match?(status)
|
||
7 years ago
|
text_matcher.matches?(prepare_text(status.text)) ||
|
||
|
text_matcher.matches?(prepare_text(status.spoiler_text)) ||
|
||
7 years ago
|
tag_matcher.matches?(status.tags)
|
||
|
end
|
||
7 years ago
|
|
||
|
def prepare_text(text)
|
||
7 years ago
|
entity_decoder.decode(strip_tags(text)).tap { |x| puts x }
|
||
7 years ago
|
end
|
||
7 years ago
|
end
|