about summary refs log tree commit diff
path: root/app/services/fetch_remote_resource_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/fetch_remote_resource_service.rb')
-rw-r--r--app/services/fetch_remote_resource_service.rb33
1 files changed, 27 insertions, 6 deletions
diff --git a/app/services/fetch_remote_resource_service.rb b/app/services/fetch_remote_resource_service.rb
index 2c1c1f05f..341664272 100644
--- a/app/services/fetch_remote_resource_service.rb
+++ b/app/services/fetch_remote_resource_service.rb
@@ -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
 
@@ -31,7 +33,26 @@ class FetchRemoteResourceService < BaseService
   end
 
   def body
-    fetched_atom_feed.last
+    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