2017-05-29 18:22:22 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusPolicy
|
|
|
|
attr_reader :account, :status
|
|
|
|
|
|
|
|
def initialize(account, status)
|
|
|
|
@account = account
|
|
|
|
@status = status
|
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
2017-05-30 15:16:14 +02:00
|
|
|
if direct?
|
2017-05-29 18:22:22 +02:00
|
|
|
status.account.id == account&.id || status.mentions.where(account: account).exists?
|
2017-05-30 15:16:14 +02:00
|
|
|
elsif private?
|
2017-05-29 18:22:22 +02:00
|
|
|
status.account.id == account&.id || account&.following?(status.account) || status.mentions.where(account: account).exists?
|
|
|
|
else
|
|
|
|
account.nil? || !status.account.blocking?(account)
|
|
|
|
end
|
|
|
|
end
|
2017-05-30 15:16:14 +02:00
|
|
|
|
|
|
|
def reblog?
|
|
|
|
!direct? && !private? && show?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def direct?
|
|
|
|
status.direct_visibility?
|
|
|
|
end
|
|
|
|
|
|
|
|
def private?
|
|
|
|
status.private_visibility?
|
|
|
|
end
|
2017-05-29 18:22:22 +02:00
|
|
|
end
|