about summary refs log tree commit diff
path: root/app/policies/status_policy.rb
blob: 658ba6d12331f2375059c900a745313d29731606 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class StatusPolicy
  attr_reader :account, :status

  def initialize(account, status)
    @account = account
    @status = status
  end

  def show?
    if status.direct_visibility?
      status.account.id == account&.id || status.mentions.where(account: account).exists?
    elsif status.private_visibility?
      status.account.id == account&.id || account&.following?(status.account) || status.mentions.where(account: account).exists?
    else
      account.nil? || !status.account.blocking?(account)
    end
  end
end