about summary refs log tree commit diff
path: root/app/services/activitypub/fetch_replies_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/activitypub/fetch_replies_service.rb')
-rw-r--r--app/services/activitypub/fetch_replies_service.rb27
1 files changed, 16 insertions, 11 deletions
diff --git a/app/services/activitypub/fetch_replies_service.rb b/app/services/activitypub/fetch_replies_service.rb
index a398bbc79..64a7dc9de 100644
--- a/app/services/activitypub/fetch_replies_service.rb
+++ b/app/services/activitypub/fetch_replies_service.rb
@@ -1,26 +1,31 @@
 # frozen_string_literal: true
 
 class ActivityPub::FetchRepliesService < BaseService
-  def call(parent_status, collection_or_uri, allow_synchronous_requests = true)
-    @parent_status = parent_status
-    @collection_or_uri = collection_or_uri
-    @allow_synchronous_requests = allow_synchronous_requests
+  def call(parent_status, collection, **options)
+    @account = parent_status.account
 
-    items = fetch_collection_items
-    return if items.blank?
+    fetch_collection_items(collection, **options)
+    return if collection.is_a?(String) && collection == @account.outbox_url
 
-    FetchReplyWorker.push_bulk(items)
-    items
+    fetch_collection_items(@account.outbox_url, **options) unless @account.silenced?
+  rescue ActiveRecord::RecordNotFound
+    nil
   end
 
   private
 
-  def fetch_collection_items
+  def fetch_collection_items(collection, **options)
     ActivityPub::FetchCollectionItemsService.new.call(
-      @collection_or_uri, @parent_status&.account,
+      collection,
+      @account,
       page_limit: 1,
       item_limit: 20,
-      allow_synchronous_requests: @allow_synchronous_requests
+      **options
     )
+  rescue Mastodon::RaceConditionError, Mastodon::UnexpectedResponseError
+    collection_uri = collection.is_a?(Hash) ? collection['id'] : collection
+    return unless collection_uri.present? && collection_uri.is_a?(String)
+
+    ActivityPub::FetchRepliesWorker.perform_async(@account.id, collection_uri)
   end
 end