Add searchability support

This commit is contained in:
KMY 2023-04-06 04:27:52 +09:00
parent a2e674af51
commit af20b1d2aa
43 changed files with 716 additions and 65 deletions

View file

@ -29,6 +29,7 @@ class ActivityPub::ProcessAccountService < BaseService
@account ||= Account.find_remote(@username, @domain)
@old_public_key = @account&.public_key
@old_protocol = @account&.protocol
@old_searchability = @account&.searchability
@suspension_changed = false
if @account.nil?
@ -112,6 +113,7 @@ class ActivityPub::ProcessAccountService < BaseService
@account.fields = property_values || {}
@account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) }
@account.discoverable = @json['discoverable'] || false
@account.searchability = searchability_from_audience
end
def set_fetchable_key!
@ -150,6 +152,10 @@ class ActivityPub::ProcessAccountService < BaseService
end
end
def after_searchability_change!
SearchabilityUpdateWorker.perform_async(@account.id) if @account.statuses.unset_searchability.exists?
end
def after_protocol_change!
ActivityPub::PostUpgradeWorker.perform_async(@account.domain)
end
@ -224,6 +230,24 @@ class ActivityPub::ProcessAccountService < BaseService
end
end
def audience_searchable_by
return nil if @json['searchableBy'].nil?
@audience_searchable_by = as_array(@json['searchableBy']).map { |x| value_or_id(x) }
end
def searchability_from_audience
if audience_searchable_by.nil?
:direct
elsif audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) }
:public
elsif audience_searchable_by.include?(@account.followers_url)
:private
else
:direct
end
end
def property_values
return unless @json['attachment'].is_a?(Array)
@ -310,6 +334,10 @@ class ActivityPub::ProcessAccountService < BaseService
!@old_protocol.nil? && @old_protocol != @account.protocol
end
def searchability_changed?
!@old_searchability.nil? && @old_searchability != @account.searchability
end
def process_tags
return if @json['tag'].blank?