]> cat aescling's git repositories - mastodon.git/commitdiff
Add support for searching AP users (#4599)
authorYamagishi Kazutoshi <ykzts@desire.sh>
Mon, 14 Aug 2017 12:08:34 +0000 (21:08 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 14 Aug 2017 12:08:34 +0000 (14:08 +0200)
* Add support for searching AP users

* use JsonLdHelper

app/services/fetch_remote_account_service.rb
app/services/fetch_remote_resource_service.rb
app/services/fetch_remote_status_service.rb
spec/services/fetch_remote_resource_service_spec.rb

index 41b5374b4fcff2ca3b03e9c618a661e2a8c64d1e..7c618a0b0c905a91951cf0ccd839ec309d199e06 100644 (file)
@@ -3,13 +3,12 @@
 class FetchRemoteAccountService < BaseService
   include AuthorExtractor
 
-  def call(url, prefetched_body = nil)
+  def call(url, prefetched_body = nil, protocol = :ostatus)
     if prefetched_body.nil?
       resource_url, body, protocol = FetchAtomService.new.call(url)
     else
       resource_url = url
       body         = prefetched_body
-      protocol     = :ostatus
     end
 
     case protocol
index 6e5830b0dccaaa7f7f654e873927ce5e741a3a29..341664272aae0a93e40c3d860dd22d0cc0004df8 100644 (file)
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class FetchRemoteResourceService < BaseService
+  include JsonLdHelper
+
   attr_reader :url
 
   def call(url)
@@ -14,11 +16,11 @@ class FetchRemoteResourceService < BaseService
   private
 
   def process_url
-    case xml_root
-    when 'feed'
-      FetchRemoteAccountService.new.call(atom_url, body)
-    when 'entry'
-      FetchRemoteStatusService.new.call(atom_url, body)
+    case type
+    when 'Person'
+      FetchRemoteAccountService.new.call(atom_url, body, protocol)
+    when 'Note'
+      FetchRemoteStatusService.new.call(atom_url, body, protocol)
     end
   end
 
@@ -34,6 +36,25 @@ class FetchRemoteResourceService < BaseService
     fetched_atom_feed.second
   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
     xml_data.root.name
   end
index 30d8d25386b8a14e644d17742a8cc22d52a130ae..18af18059b666a7623f9e3f055cd97297da6d10c 100644 (file)
@@ -3,13 +3,12 @@
 class FetchRemoteStatusService < BaseService
   include AuthorExtractor
 
-  def call(url, prefetched_body = nil)
+  def call(url, prefetched_body = nil, protocol = :ostatus)
     if prefetched_body.nil?
       resource_url, body, protocol = FetchAtomService.new.call(url)
     else
       resource_url = url
       body         = prefetched_body
-      protocol     = :ostatus
     end
 
     case protocol
index 81b0e48e32eb4369e87e3730cd3f36a84d957ed0..c14fcfc4e6c05b804a6c601da527982beea34591 100644 (file)
@@ -30,7 +30,7 @@ describe FetchRemoteResourceService do
 
       _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
 
     it 'fetches remote statuses for entry types' do
@@ -47,7 +47,7 @@ describe FetchRemoteResourceService do
 
       _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