2017-05-29 16:22:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
class StatusPolicy < ApplicationPolicy
|
2021-07-16 06:38:50 +00:00
|
|
|
def initialize(current_account, record, preloaded_account_relations = {}, preloaded_status_relations = {})
|
2018-05-03 08:41:58 +00:00
|
|
|
super(current_account, record)
|
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
@preloaded_account_relations = preloaded_account_relations
|
|
|
|
@preloaded_status_relations = preloaded_status_relations
|
2018-05-03 08:41:58 +00:00
|
|
|
end
|
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
delegate :reply?, :expired?, to: :record
|
2020-09-05 07:33:17 +00:00
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
def index?
|
|
|
|
staff?
|
2017-05-29 16:22:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
2020-09-11 13:16:29 +00:00
|
|
|
return false if author.suspended?
|
2021-07-16 06:38:50 +00:00
|
|
|
return false unless expired_show?
|
2020-09-11 13:16:29 +00:00
|
|
|
|
2018-10-17 15:13:04 +00:00
|
|
|
if requires_mention?
|
2018-05-03 08:41:58 +00:00
|
|
|
owned? || mention_exists?
|
2017-05-30 13:16:14 +00:00
|
|
|
elsif private?
|
2018-05-03 08:41:58 +00:00
|
|
|
owned? || following_author? || mention_exists?
|
2017-05-29 16:22:22 +00:00
|
|
|
else
|
2019-07-16 23:53:37 +00:00
|
|
|
current_account.nil? || (!author_blocking? && !author_blocking_domain?)
|
2017-05-29 16:22:22 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-30 13:16:14 +00:00
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
def expired_show?
|
|
|
|
!expired? || owned? || favourited_status? || bookmarked_status? || emoji_reactioned_status?
|
|
|
|
end
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
def reblog?
|
2018-10-17 15:13:04 +00:00
|
|
|
!requires_mention? && (!private? || owned?) && show? && !blocking_author?
|
2018-05-02 13:50:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def favourite?
|
2018-05-03 08:41:58 +00:00
|
|
|
show? && !blocking_author?
|
2017-05-30 13:16:14 +00:00
|
|
|
end
|
|
|
|
|
2017-05-30 20:56:31 +00:00
|
|
|
def destroy?
|
2017-11-11 19:23:33 +00:00
|
|
|
staff? || owned?
|
2017-05-30 20:56:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
alias unreblog? destroy?
|
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
def update?
|
|
|
|
staff?
|
2017-05-30 20:56:31 +00:00
|
|
|
end
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
def show_mentions?
|
|
|
|
limited? && owned? && (!reply? || record.thread.conversation_id != record.conversation_id)
|
|
|
|
end
|
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
private
|
|
|
|
|
2018-10-17 15:13:04 +00:00
|
|
|
def requires_mention?
|
|
|
|
record.direct_visibility? || record.limited_visibility?
|
2017-05-30 13:16:14 +00:00
|
|
|
end
|
|
|
|
|
2017-05-30 20:56:31 +00:00
|
|
|
def owned?
|
2017-11-11 19:23:33 +00:00
|
|
|
author.id == current_account&.id
|
2017-05-30 20:56:31 +00:00
|
|
|
end
|
|
|
|
|
2017-05-30 13:16:14 +00:00
|
|
|
def private?
|
2017-11-11 19:23:33 +00:00
|
|
|
record.private_visibility?
|
|
|
|
end
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
def limited?
|
|
|
|
record.limited_visibility?
|
|
|
|
end
|
|
|
|
|
2018-05-03 08:41:58 +00: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
|
|
|
|
record.mentions.where(account: current_account).exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-16 23:53:37 +00:00
|
|
|
def author_blocking_domain?
|
|
|
|
return false if current_account.nil? || current_account.domain.nil?
|
|
|
|
|
2019-07-17 22:48:26 +00:00
|
|
|
author.domain_blocking?(current_account.domain)
|
2019-07-16 23:53:37 +00:00
|
|
|
end
|
|
|
|
|
2018-05-03 08:41:58 +00:00
|
|
|
def blocking_author?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
@preloaded_account_relations[:blocking] ? @preloaded_account_relations[:blocking][author.id] : current_account.blocking?(author)
|
2018-05-03 08:41:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def author_blocking?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
@preloaded_account_relations[:blocked_by] ? @preloaded_account_relations[:blocked_by][author.id] : author.blocking?(current_account)
|
2018-05-03 08:41:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def following_author?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
2021-07-16 06:38:50 +00:00
|
|
|
@preloaded_account_relations[:following] ? @preloaded_account_relations[:following][author.id] : current_account.following?(author)
|
|
|
|
end
|
|
|
|
|
|
|
|
def favourited_status?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_status_relations[:favourites_map] ? @preloaded_status_relations[:favourites_map][record.id] : current_account.favourited?(record)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bookmarked_status?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_status_relations[:bookmarks_map] ? @preloaded_status_relations[:bookmarks_map][record.id] : current_account.bookmarked?(record)
|
|
|
|
end
|
|
|
|
|
|
|
|
def emoji_reactioned_status?
|
|
|
|
return false if current_account.nil?
|
|
|
|
|
|
|
|
@preloaded_status_relations[:emoji_reactions_map] ? @preloaded_status_relations[:emoji_reactions_map][record.id] : current_account.emoji_reactioned?(record)
|
2018-05-03 08:41:58 +00:00
|
|
|
end
|
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
def author
|
|
|
|
record.account
|
2017-05-30 13:16:14 +00:00
|
|
|
end
|
2017-05-29 16:22:22 +00:00
|
|
|
end
|