mirror of
https://github.com/kikobar/mastodon.git
synced 2024-12-26 15:54:23 +00:00
dd7ef0dc41
* Add ActivityPub inbox * Handle ActivityPub deletes * Handle ActivityPub creates * Handle ActivityPub announces * Stubs for handling all activities that need to be handled * Add ActivityPub actor resolving * Handle conversation URI passing in ActivityPub * Handle content language in ActivityPub * Send accept header when fetching actor, handle JSON parse errors * Test for ActivityPub::FetchRemoteAccountService * Handle public key and icon/image when embedded/as array/as resolvable URI * Implement ActivityPub::FetchRemoteStatusService * Add stubs for more interactions * Undo activities implemented * Handle out of order activities * Hook up ActivityPub to ResolveRemoteAccountService, handle Update Account activities * Add fragment IDs to all transient activity serializers * Add tests and fixes * Add stubs for missing tests * Add more tests * Add more tests
37 lines
1 KiB
Ruby
37 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ActivityPub::FetchRemoteStatusService < BaseService
|
|
include JsonLdHelper
|
|
|
|
# Should be called when uri has already been checked for locality
|
|
def call(uri)
|
|
@json = fetch_resource(uri)
|
|
|
|
return unless supported_context? && expected_type?
|
|
|
|
attributed_to = first_of_value(@json['attributedTo'])
|
|
attributed_to = attributed_to['id'] if attributed_to.is_a?(Hash)
|
|
|
|
return unless trustworthy_attribution?(uri, attributed_to)
|
|
|
|
actor = ActivityPub::TagManager.instance.uri_to_resource(attributed_to, Account)
|
|
actor = ActivityPub::FetchRemoteAccountService.new.call(attributed_to) if actor.nil?
|
|
|
|
ActivityPub::Activity::Create.new({ 'object' => @json }, actor).perform
|
|
end
|
|
|
|
private
|
|
|
|
def trustworthy_attribution?(uri, attributed_to)
|
|
Addressable::URI.parse(uri).normalized_host.casecmp(Addressable::URI.parse(attributed_to).normalized_host).zero?
|
|
end
|
|
|
|
def supported_context?
|
|
super(@json)
|
|
end
|
|
|
|
def expected_type?
|
|
%w(Note Article).include? @json['type']
|
|
end
|
|
end
|