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.
 
 
 
 

59 lines
1.6 KiB

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