Support Actors/Statuses with multiple types (#7305)
* Add equals_or_includes_any? helper in JsonLdHelper * Support arrays in JSON-LD type fields for actors/tags/objects. * Spec for resolving accounts with extension types * Style tweaks for codeclimate
This commit is contained in:
parent
86efccce2a
commit
dc786c0cf4
12 changed files with 43 additions and 24 deletions
|
@ -56,6 +56,6 @@ class ActivityPub::FetchRemoteAccountService < BaseService
|
|||
end
|
||||
|
||||
def expected_type?
|
||||
SUPPORTED_TYPES.include?(@json['type'])
|
||||
equals_or_includes_any?(@json['type'], SUPPORTED_TYPES)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
end
|
||||
|
||||
def person?
|
||||
ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@json['type'])
|
||||
equals_or_includes_any?(@json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES)
|
||||
end
|
||||
|
||||
def public_key?
|
||||
|
@ -55,6 +55,6 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
end
|
||||
|
||||
def confirmed_owner?
|
||||
ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@owner['type']) && value_or_id(@owner['publicKey']) == @json['id']
|
||||
equals_or_includes_any?(@owner['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) && value_or_id(@owner['publicKey']) == @json['id']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ class ActivityPub::FetchRemoteStatusService < BaseService
|
|||
end
|
||||
|
||||
def expected_type?
|
||||
(ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES).include? @json['type']
|
||||
equals_or_includes_any?(@json['type'], ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES)
|
||||
end
|
||||
|
||||
def needs_update(actor)
|
||||
|
|
|
@ -201,10 +201,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
return if @json['tag'].blank?
|
||||
|
||||
as_array(@json['tag']).each do |tag|
|
||||
case tag['type']
|
||||
when 'Emoji'
|
||||
process_emoji tag
|
||||
end
|
||||
process_emoji tag if equals_or_includes?(tag['type'], 'Emoji')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class FetchAtomService < BaseService
|
|||
elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type)
|
||||
body = response.body_with_limit
|
||||
json = body_to_json(body)
|
||||
if supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) && json['inbox'].present?
|
||||
if supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) && json['inbox'].present?
|
||||
[json['id'], { prefetched_body: body, id: true }, :activitypub]
|
||||
elsif supported_context?(json) && expected_type?(json)
|
||||
[json['id'], { prefetched_body: body, id: true }, :activitypub]
|
||||
|
@ -62,7 +62,7 @@ class FetchAtomService < BaseService
|
|||
end
|
||||
|
||||
def expected_type?(json)
|
||||
(ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES).include? json['type']
|
||||
equals_or_includes_any?(json['type'], ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES)
|
||||
end
|
||||
|
||||
def process_html(response)
|
||||
|
|
|
@ -189,7 +189,7 @@ class ResolveAccountService < BaseService
|
|||
return @actor_json if defined?(@actor_json)
|
||||
|
||||
json = fetch_resource(actor_url, false)
|
||||
@actor_json = supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) ? json : nil
|
||||
@actor_json = supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) ? json : nil
|
||||
end
|
||||
|
||||
def atom
|
||||
|
|
|
@ -16,10 +16,9 @@ class ResolveURLService < BaseService
|
|||
private
|
||||
|
||||
def process_url
|
||||
case type
|
||||
when 'Application', 'Group', 'Organization', 'Person', 'Service'
|
||||
if equals_or_includes_any?(type, %w(Application Group Organization Person Service))
|
||||
FetchRemoteAccountService.new.call(atom_url, body, protocol)
|
||||
when 'Note', 'Article', 'Image', 'Video'
|
||||
elsif equals_or_includes_any?(type, %w(Note Article Image Video))
|
||||
FetchRemoteStatusService.new.call(atom_url, body, protocol)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue