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.

27 lines
723 B

  1. require 'html2text'
  2. class Glitch::KeywordMuteHelper
  3. attr_reader :text_matcher
  4. attr_reader :tag_matcher
  5. def initialize(receiver_id)
  6. @text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
  7. @tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
  8. end
  9. def matches?(status, scope)
  10. matchers_match?(status, scope) || (status.reblog? && matchers_match?(status.reblog, scope))
  11. end
  12. private
  13. def matchers_match?(status, scope)
  14. text_matcher.matches?(prepare_text(status.text), scope) ||
  15. text_matcher.matches?(prepare_text(status.spoiler_text), scope) ||
  16. tag_matcher.matches?(status.tags, scope)
  17. end
  18. def prepare_text(text)
  19. Html2Text.convert(text)
  20. end
  21. end