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
674 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)
  10. matchers_match?(status) || (status.reblog? && matchers_match?(status.reblog))
  11. end
  12. private
  13. def matchers_match?(status)
  14. text_matcher.matches?(prepare_text(status.text)) ||
  15. text_matcher.matches?(prepare_text(status.spoiler_text)) ||
  16. tag_matcher.matches?(status.tags)
  17. end
  18. def prepare_text(text)
  19. Html2Text.convert(text)
  20. end
  21. end