From 78751251df71f16bedc184d70d75f3280db86184 Mon Sep 17 00:00:00 2001 From: jonny Date: Wed, 8 May 2024 01:55:55 -0700 Subject: [PATCH] committing all ugly with a bunch of logger calls in the middle but we are almost there baby Signed-off-by: sneakers-the-rat --- app/controllers/api/v1/statuses_controller.rb | 26 +++++++++++++------ .../activitypub/fetch_replies_service.rb | 11 ++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index dbf7852dfe..f008a3fe95 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -2,6 +2,7 @@ class Api::V1::StatusesController < Api::BaseController include Authorization + include JsonLdHelper before_action -> { authorize_if_got_token! :read, :'read:statuses' }, except: [:create, :update, :destroy] before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: [:create, :update, :destroy] @@ -48,15 +49,24 @@ class Api::V1::StatusesController < Api::BaseController descendants_limit = DESCENDANTS_LIMIT descendants_depth_limit = DESCENDANTS_DEPTH_LIMIT else - collection = @status['replies'] + unless @status.local? + json_status = fetch_resource(@status.uri, true, @current_account) - unless collection.nil? && @status.local? - ActivityPub::FetchRepliesService.new.call( - value_or_id(@status), - value_or_id(collection), - allow_synchronous_requests: true, - all_replies: true - ) + logger.warn "json status" + logger.warn json_status + # rescue this whole block on failure, don't want to fail the whole context request if we can't do this + collection = json_status['replies'] + logger.warn "replies uri" + logger.warn collection + + unless collection.nil? + ActivityPub::FetchRepliesService.new.call( + @status, + collection, + allow_synchronous_requests: true, + all_replies: true + ) + end end end diff --git a/app/services/activitypub/fetch_replies_service.rb b/app/services/activitypub/fetch_replies_service.rb index f2fa1c2596..c516fe759d 100644 --- a/app/services/activitypub/fetch_replies_service.rb +++ b/app/services/activitypub/fetch_replies_service.rb @@ -15,6 +15,9 @@ class ActivityPub::FetchRepliesService < BaseService @allow_synchronous_requests = allow_synchronous_requests @items = collection_items(collection_or_uri) + logger = Logger.new(STDOUT) + logger.warn 'collection items' + logger.warn @items return if @items.nil? FetchReplyWorker.push_bulk(filtered_replies) { |reply_uri| [reply_uri, { 'request_id' => request_id }] } @@ -25,12 +28,20 @@ class ActivityPub::FetchRepliesService < BaseService private def collection_items(collection_or_uri) + logger = Logger.new(STDOUT) collection = fetch_collection(collection_or_uri) + logger.warn 'first collection' + logger.warn collection return unless collection.is_a?(Hash) collection = fetch_collection(collection['first']) if collection['first'].present? + logger.warn 'second collection' + logger.warn collection return unless collection.is_a?(Hash) + # Need to do another "next" here. see https://neuromatch.social/users/jonny/statuses/112401738180959195/replies for example + # then we are home free (stopping for tonight tho.) + case collection['type'] when 'Collection', 'CollectionPage' as_array(collection['items'])