# frozen_string_literal: true
class StatusPolicy < ApplicationPolicy
def initialize(current_account, record, preloaded_relations = {})
super(current_account, record)
@preloaded_relations = preloaded_relations
end
def show?
return false if author.suspended?
if requires_mention?
owned? || mention_exists?
elsif private?
owned? || following_author? || mention_exists?
else
current_account.nil? || (!author_blocking? && !author_blocking_domain?)
def reblog?
!requires_mention? && (!private? || owned?) && show? && !blocking_author?
def favourite?
show? && !blocking_author?
def destroy?
owned?
alias unreblog? destroy?
def update?
private
def requires_mention?
record.direct_visibility? || record.limited_visibility?
def owned?
author.id == current_account&.id
def private?
record.private_visibility?
def mention_exists?
return false if current_account.nil?
if record.mentions.loaded?
record.mentions.any? { |mention| mention.account_id == current_account.id }
record.mentions.where(account: current_account).exists?
def author_blocking_domain?
return false if current_account.nil? || current_account.domain.nil?
author.domain_blocking?(current_account.domain)
def blocking_author?
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][author.id] : current_account.blocking?(author)
def author_blocking?
@preloaded_relations[:blocked_by] ? @preloaded_relations[:blocked_by][author.id] : author.blocking?(current_account)
def following_author?
@preloaded_relations[:following] ? @preloaded_relations[:following][author.id] : current_account.following?(author)
def author
record.account