The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
810 B

  1. # frozen_string_literal: true
  2. class StatusPolicy
  3. attr_reader :account, :status
  4. def initialize(account, status)
  5. @account = account
  6. @status = status
  7. end
  8. def show?
  9. if direct?
  10. owned? || status.mentions.where(account: account).exists?
  11. elsif private?
  12. owned? || account&.following?(status.account) || status.mentions.where(account: account).exists?
  13. else
  14. account.nil? || !status.account.blocking?(account)
  15. end
  16. end
  17. def reblog?
  18. !direct? && !private? && show?
  19. end
  20. def destroy?
  21. admin? || owned?
  22. end
  23. alias unreblog? destroy?
  24. private
  25. def admin?
  26. account&.user&.admin?
  27. end
  28. def direct?
  29. status.direct_visibility?
  30. end
  31. def owned?
  32. status.account.id == account&.id
  33. end
  34. def private?
  35. status.private_visibility?
  36. end
  37. end