mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-26 22:36:21 +01:00
Add support for searching AP users (#4599)
* Add support for searching AP users * use JsonLdHelper
This commit is contained in:
parent
26d26644ac
commit
5f22c0189d
@ -3,13 +3,12 @@
|
|||||||
class FetchRemoteAccountService < BaseService
|
class FetchRemoteAccountService < BaseService
|
||||||
include AuthorExtractor
|
include AuthorExtractor
|
||||||
|
|
||||||
def call(url, prefetched_body = nil)
|
def call(url, prefetched_body = nil, protocol = :ostatus)
|
||||||
if prefetched_body.nil?
|
if prefetched_body.nil?
|
||||||
resource_url, body, protocol = FetchAtomService.new.call(url)
|
resource_url, body, protocol = FetchAtomService.new.call(url)
|
||||||
else
|
else
|
||||||
resource_url = url
|
resource_url = url
|
||||||
body = prefetched_body
|
body = prefetched_body
|
||||||
protocol = :ostatus
|
|
||||||
end
|
end
|
||||||
|
|
||||||
case protocol
|
case protocol
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FetchRemoteResourceService < BaseService
|
class FetchRemoteResourceService < BaseService
|
||||||
|
include JsonLdHelper
|
||||||
|
|
||||||
attr_reader :url
|
attr_reader :url
|
||||||
|
|
||||||
def call(url)
|
def call(url)
|
||||||
@ -14,11 +16,11 @@ class FetchRemoteResourceService < BaseService
|
|||||||
private
|
private
|
||||||
|
|
||||||
def process_url
|
def process_url
|
||||||
case xml_root
|
case type
|
||||||
when 'feed'
|
when 'Person'
|
||||||
FetchRemoteAccountService.new.call(atom_url, body)
|
FetchRemoteAccountService.new.call(atom_url, body, protocol)
|
||||||
when 'entry'
|
when 'Note'
|
||||||
FetchRemoteStatusService.new.call(atom_url, body)
|
FetchRemoteStatusService.new.call(atom_url, body, protocol)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,6 +36,25 @@ class FetchRemoteResourceService < BaseService
|
|||||||
fetched_atom_feed.second
|
fetched_atom_feed.second
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def protocol
|
||||||
|
fetched_atom_feed.third
|
||||||
|
end
|
||||||
|
|
||||||
|
def type
|
||||||
|
return json_data['type'] if protocol == :activitypub
|
||||||
|
|
||||||
|
case xml_root
|
||||||
|
when 'feed'
|
||||||
|
'Person'
|
||||||
|
when 'entry'
|
||||||
|
'Note'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def json_data
|
||||||
|
@_json_data ||= body_to_json(body)
|
||||||
|
end
|
||||||
|
|
||||||
def xml_root
|
def xml_root
|
||||||
xml_data.root.name
|
xml_data.root.name
|
||||||
end
|
end
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
class FetchRemoteStatusService < BaseService
|
class FetchRemoteStatusService < BaseService
|
||||||
include AuthorExtractor
|
include AuthorExtractor
|
||||||
|
|
||||||
def call(url, prefetched_body = nil)
|
def call(url, prefetched_body = nil, protocol = :ostatus)
|
||||||
if prefetched_body.nil?
|
if prefetched_body.nil?
|
||||||
resource_url, body, protocol = FetchAtomService.new.call(url)
|
resource_url, body, protocol = FetchAtomService.new.call(url)
|
||||||
else
|
else
|
||||||
resource_url = url
|
resource_url = url
|
||||||
body = prefetched_body
|
body = prefetched_body
|
||||||
protocol = :ostatus
|
|
||||||
end
|
end
|
||||||
|
|
||||||
case protocol
|
case protocol
|
||||||
|
@ -30,7 +30,7 @@ describe FetchRemoteResourceService do
|
|||||||
|
|
||||||
_result = subject.call(url)
|
_result = subject.call(url)
|
||||||
|
|
||||||
expect(account_service).to have_received(:call).with(feed_url, feed_content)
|
expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches remote statuses for entry types' do
|
it 'fetches remote statuses for entry types' do
|
||||||
@ -47,7 +47,7 @@ describe FetchRemoteResourceService do
|
|||||||
|
|
||||||
_result = subject.call(url)
|
_result = subject.call(url)
|
||||||
|
|
||||||
expect(account_service).to have_received(:call).with(feed_url, feed_content)
|
expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user