The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

58 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class StatusFilter
  3. attr_reader :status, :account
  4. def initialize(status, account)
  5. @status = status
  6. @account = account
  7. end
  8. def filtered?
  9. return false if !account.nil? && account.id == status.account_id
  10. blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
  11. end
  12. private
  13. def account_present?
  14. !account.nil?
  15. end
  16. def filtered_status?
  17. blocking_account? || blocking_domain? || muting_account?
  18. end
  19. def blocking_account?
  20. account.blocking? status.account_id
  21. end
  22. def blocking_domain?
  23. account.domain_blocking? status.account_domain
  24. end
  25. def muting_account?
  26. account.muting? status.account_id
  27. end
  28. def silenced_account?
  29. !account&.silenced? && status_account_silenced? && !account_following_status_account?
  30. end
  31. def status_account_silenced?
  32. status.account.silenced?
  33. end
  34. def account_following_status_account?
  35. account&.following? status.account_id
  36. end
  37. def blocked_by_policy?
  38. !policy_allows_show?
  39. end
  40. def policy_allows_show?
  41. StatusPolicy.new(account, status).show?
  42. end
  43. end