2018-02-11 01:32:14 +09:00
|
|
|
require 'html2text'
|
2017-12-04 12:40:28 +09:00
|
|
|
|
2017-12-04 12:49:55 +09:00
|
|
|
class Glitch::KeywordMuteHelper
|
2017-12-04 08:28:30 +09:00
|
|
|
attr_reader :text_matcher
|
|
|
|
attr_reader :tag_matcher
|
|
|
|
|
|
|
|
def initialize(receiver_id)
|
2017-12-04 12:40:28 +09:00
|
|
|
@text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
|
|
|
|
@tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
|
2017-12-04 08:28:30 +09:00
|
|
|
end
|
|
|
|
|
2018-06-04 09:41:54 +09:00
|
|
|
def matches?(status, scope)
|
|
|
|
matchers_match?(status, scope) || (status.reblog? && matchers_match?(status.reblog, scope))
|
2017-12-04 08:28:30 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-06-04 09:41:54 +09:00
|
|
|
def matchers_match?(status, scope)
|
|
|
|
text_matcher.matches?(prepare_text(status.text), scope) ||
|
|
|
|
text_matcher.matches?(prepare_text(status.spoiler_text), scope) ||
|
|
|
|
tag_matcher.matches?(status.tags, scope)
|
2017-12-04 08:28:30 +09:00
|
|
|
end
|
2017-12-04 12:40:28 +09:00
|
|
|
|
|
|
|
def prepare_text(text)
|
2018-02-11 01:32:14 +09:00
|
|
|
Html2Text.convert(text)
|
2017-12-04 12:40:28 +09:00
|
|
|
end
|
2017-12-04 08:28:30 +09:00
|
|
|
end
|