mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add support for FEP-2c59 (#38239)
This commit is contained in:
@@ -4,6 +4,7 @@ module ContextHelper
|
||||
NAMED_CONTEXT_MAP = {
|
||||
activitystreams: 'https://www.w3.org/ns/activitystreams',
|
||||
security: 'https://w3id.org/security/v1',
|
||||
webfinger: 'https://purl.archive.org/socialweb/webfinger',
|
||||
}.freeze
|
||||
|
||||
CONTEXT_EXTENSION_MAP = {
|
||||
|
||||
@@ -4,7 +4,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
include FormattingHelper
|
||||
|
||||
context :security
|
||||
context :security, :webfinger
|
||||
|
||||
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
||||
:moved_to, :property_value, :discoverable, :suspended,
|
||||
@@ -55,6 +55,10 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def webfinger
|
||||
object.local_username_and_domain
|
||||
end
|
||||
|
||||
def type
|
||||
if object.instance_actor?
|
||||
'Application'
|
||||
|
||||
@@ -27,11 +27,23 @@ class ActivityPub::FetchRemoteActorService < BaseService
|
||||
raise Error, "Unsupported JSON-LD context for document #{uri}" unless supported_context?
|
||||
raise Error, "Unexpected object type for actor #{uri} (expected any of: #{SUPPORTED_TYPES})" unless expected_type?
|
||||
raise Error, "Actor #{uri} has moved to #{@json['movedTo']}" if break_on_redirect && @json['movedTo'].present?
|
||||
raise Error, "Actor #{uri} has no 'preferredUsername', which is a requirement for Mastodon compatibility" if @json['preferredUsername'].blank?
|
||||
raise Error, "Actor #{uri} has neither 'preferredUsername' nor `webfinger`, which is a requirement for Mastodon compatibility" if @json['preferredUsername'].blank? && @json['webfinger'].blank?
|
||||
|
||||
@uri = @json['id']
|
||||
@username = @json['preferredUsername']
|
||||
@domain = Addressable::URI.parse(@uri).normalized_host
|
||||
@uri = @json['id']
|
||||
|
||||
# FEP-2c59 defines a `webfinger` attribute that makes things more explicit and spares an extra request in some cases.
|
||||
# It supersedes `preferredUsername`.
|
||||
if @json['webfinger'].present? && @json['webfinger'].is_a?(String)
|
||||
@username, @domain = split_acct(@json['webfinger'])
|
||||
Rails.logger.debug { "Actor #{uri} has an invalid `webfinger` value, falling back to `preferredUsername`" }
|
||||
end
|
||||
|
||||
if @username.blank? || @domain.blank?
|
||||
raise "Actor #{uri} has no `preferredUsername`, and either a bogus or missing `webfinger`, which is a requirement for Mastodon compatibility" if @json['preferredUsername'].blank?
|
||||
|
||||
@username = @json['preferredUsername']
|
||||
@domain = Addressable::URI.parse(@uri).normalized_host
|
||||
end
|
||||
|
||||
check_webfinger! unless only_key
|
||||
|
||||
|
||||
Reference in New Issue
Block a user