2017-05-29 12:22:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
class StatusPolicy < ApplicationPolicy
|
2018-05-03 04:41:58 -04:00
|
|
|
def initialize(current_account, record, preloaded_relations = {})
|
|
|
|
super(current_account, record)
|
|
|
|
|
|
|
|
@preloaded_relations = preloaded_relations
|
|
|
|
end
|
|
|
|
|
2017-05-29 12:22:22 -04:00
|
|
|
def show?
|
2023-11-30 10:43:26 -05:00
|
|
|
return false if author.unavailable?
|
2020-09-11 09:16:29 -04:00
|
|
|
|
2018-10-17 11:13:04 -04:00
|
|
|
if requires_mention?
|
2018-05-03 04:41:58 -04:00
|
|
|
owned? || mention_exists?
|
2017-05-30 09:16:14 -04:00
|
|
|
elsif private?
|
2018-05-03 04:41:58 -04:00
|
|
|
owned? || following_author? || mention_exists?
|
2017-05-29 12:22:22 -04:00
|
|
|
else
|
2019-07-16 19:53:37 -04:00
|
|
|
current_account.nil? || (!author_blocking? && !author_blocking_domain?)
|
2017-05-29 12:22:22 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-30 09:16:14 -04:00
|
|
|
|
|
|
|
def reblog?
|
2018-10-17 11:13:04 -04:00
|
|
|
!requires_mention? && (!private? || owned?) && show? && !blocking_author?
|
2018-05-02 09:50:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def favourite?
|
2018-05-03 04:41:58 -04:00
|
|
|
show? && !blocking_author?
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 16:56:31 -04:00
|
|
|
def destroy?
|
2022-10-26 07:42:29 -04:00
|
|
|
owned?
|
2017-05-30 16:56:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
alias unreblog? destroy?
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
def update?
|
2022-10-26 07:42:29 -04:00
|
|
|
owned?
|
2022-02-24 18:34:14 -05:00
|
|
|
end
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
private
|
|
|
|
|
2018-10-17 11:13:04 -04:00
|
|
|
def requires_mention?
|
|
|
|
record.direct_visibility? || record.limited_visibility?
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 16:56:31 -04:00
|
|
|
def owned?
|
2017-11-11 14:23:33 -05:00
|
|
|
author.id == current_account&.id
|
2017-05-30 16:56:31 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 09:16:14 -04:00
|
|
|
def private?
|
2017-11-11 14:23:33 -05:00
|
|
|
record.private_visibility?
|
|
|
|
end
|
|
|
|
|
2018-05-03 04:41:58 -04:00
|
|
|
def mention_exists?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
if record.mentions.loaded?
|
|
|
|
record.mentions.any? { |mention| mention.account_id == current_account.id }
|
|
|
|
else
|
2024-01-25 07:37:07 -05:00
|
|
|
record.mentions.exists?(account: current_account)
|
2018-05-03 04:41:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-16 19:53:37 -04:00
|
|
|
def author_blocking_domain?
|
|
|
|
return false if current_account.nil? || current_account.domain.nil?
|
|
|
|
|
2019-07-17 18:48:26 -04:00
|
|
|
author.domain_blocking?(current_account.domain)
|
2019-07-16 19:53:37 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 04:41:58 -04:00
|
|
|
def blocking_author?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][author.id] : current_account.blocking?(author)
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_blocking?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_relations[:blocked_by] ? @preloaded_relations[:blocked_by][author.id] : author.blocking?(current_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
def following_author?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_relations[:following] ? @preloaded_relations[:following][author.id] : current_account.following?(author)
|
|
|
|
end
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
def author
|
|
|
|
record.account
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
2017-05-29 12:22:22 -04:00
|
|
|
end
|