2017-05-29 16:22:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusPolicy
|
|
|
|
attr_reader :account, :status
|
|
|
|
|
|
|
|
def initialize(account, status)
|
|
|
|
@account = account
|
|
|
|
@status = status
|
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
2017-10-09 13:56:17 +00:00
|
|
|
return false if local_only? && account.nil?
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
if direct?
|
2017-05-30 20:56:31 +00:00
|
|
|
owned? || status.mentions.where(account: account).exists?
|
2017-05-30 13:16:14 +00:00
|
|
|
elsif private?
|
2017-05-30 20:56:31 +00:00
|
|
|
owned? || account&.following?(status.account) || status.mentions.where(account: account).exists?
|
2017-05-29 16:22:22 +00:00
|
|
|
else
|
|
|
|
account.nil? || !status.account.blocking?(account)
|
|
|
|
end
|
|
|
|
end
|
2017-05-30 13:16:14 +00:00
|
|
|
|
|
|
|
def reblog?
|
|
|
|
!direct? && !private? && show?
|
|
|
|
end
|
|
|
|
|
2017-05-30 20:56:31 +00:00
|
|
|
def destroy?
|
|
|
|
admin? || owned?
|
|
|
|
end
|
|
|
|
|
|
|
|
alias unreblog? destroy?
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
private
|
|
|
|
|
2017-05-30 20:56:31 +00:00
|
|
|
def admin?
|
|
|
|
account&.user&.admin?
|
|
|
|
end
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
def direct?
|
|
|
|
status.direct_visibility?
|
|
|
|
end
|
|
|
|
|
2017-05-30 20:56:31 +00:00
|
|
|
def owned?
|
|
|
|
status.account.id == account&.id
|
|
|
|
end
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
def private?
|
|
|
|
status.private_visibility?
|
|
|
|
end
|
2017-10-09 13:56:17 +00:00
|
|
|
|
|
|
|
def local_only?
|
|
|
|
status.local_only?
|
|
|
|
end
|
2017-05-29 16:22:22 +00:00
|
|
|
end
|