Introduce StatusThreadingConcern (#3490)
* Add a StatusFilter class to identify visibility of statuses by accounts * Extract StatusThreadingConcern from Status * Clarify purpose of checking for nil account
This commit is contained in:
parent
c26cea262b
commit
6201f96b8a
6 changed files with 311 additions and 124 deletions
56
app/lib/status_filter.rb
Normal file
56
app/lib/status_filter.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StatusFilter
|
||||
attr_reader :status, :account
|
||||
|
||||
def initialize(status, account)
|
||||
@status = status
|
||||
@account = account
|
||||
end
|
||||
|
||||
def filtered?
|
||||
account_present? && filtered_status?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account_present?
|
||||
!account.nil?
|
||||
end
|
||||
|
||||
def filtered_status?
|
||||
blocking_account? || blocking_domain? || muting_account? || silenced_account? || blocked_by_policy?
|
||||
end
|
||||
|
||||
def blocking_account?
|
||||
account.blocking? status.account_id
|
||||
end
|
||||
|
||||
def blocking_domain?
|
||||
account.domain_blocking? status.account_domain
|
||||
end
|
||||
|
||||
def muting_account?
|
||||
account.muting? status.account_id
|
||||
end
|
||||
|
||||
def silenced_account?
|
||||
status_account_silenced? && !account_following_status_account?
|
||||
end
|
||||
|
||||
def status_account_silenced?
|
||||
status.account.silenced?
|
||||
end
|
||||
|
||||
def account_following_status_account?
|
||||
account.following? status.account_id
|
||||
end
|
||||
|
||||
def blocked_by_policy?
|
||||
!policy_allows_show?
|
||||
end
|
||||
|
||||
def policy_allows_show?
|
||||
StatusPolicy.new(account, status).show?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue