Put ActivityPub alternate link into Atom, prefer it when processing Atom (#4623)
This commit is contained in:
@ -29,16 +29,28 @@ class OStatus::Activity::Base
|
||||
end
|
||||
|
||||
def url
|
||||
link = @xml.at_xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS)
|
||||
link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS).find { |link_candidate| link_candidate['type'] == 'text/html' }
|
||||
link.nil? ? nil : link['href']
|
||||
end
|
||||
|
||||
def activitypub_uri
|
||||
link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS).find { |link_candidate| ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(link_candidate['type']) }
|
||||
link.nil? ? nil : link['href']
|
||||
end
|
||||
|
||||
def activitypub_uri?
|
||||
activitypub_uri.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_status(uri)
|
||||
if TagManager.instance.local_id?(uri)
|
||||
local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status')
|
||||
return Status.find_by(id: local_id)
|
||||
elsif ActivityPub::TagManager.instance.local_uri?(uri)
|
||||
local_id = ActivityPub::TagManager.instance.uri_to_local_id(uri)
|
||||
return Status.find_by(id: local_id)
|
||||
end
|
||||
|
||||
Status.find_by(uri: uri)
|
||||
|
@ -8,6 +8,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
end
|
||||
|
||||
return [nil, false] if @account.suspended?
|
||||
return perform_via_activitypub if activitypub_uri?
|
||||
|
||||
Rails.logger.debug "Creating remote status #{id}"
|
||||
|
||||
@ -52,6 +53,10 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
[status, true]
|
||||
end
|
||||
|
||||
def perform_via_activitypub
|
||||
[find_status(activitypub_uri) || ActivityPub::FetchRemoteStatusService.new.call(activitypub_uri), false]
|
||||
end
|
||||
|
||||
def content
|
||||
@xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
|
||||
end
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
class OStatus::Activity::Remote < OStatus::Activity::Base
|
||||
def perform
|
||||
find_status(id) || FetchRemoteStatusService.new.call(url)
|
||||
if activitypub_uri?
|
||||
find_status(activitypub_uri) || FetchRemoteStatusService.new.call(url)
|
||||
else
|
||||
find_status(id) || FetchRemoteStatusService.new.call(url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user