Skip to content

Commit

Permalink
committing all ugly with a bunch of logger calls in the middle but we…
Browse files Browse the repository at this point in the history
… are almost there baby
  • Loading branch information
jonny authored and sneakers-the-rat committed Sep 19, 2024
1 parent fe76c0d commit d478936
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
28 changes: 19 additions & 9 deletions app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -48,15 +49,24 @@ def context
descendants_limit = DESCENDANTS_LIMIT
descendants_depth_limit = DESCENDANTS_DEPTH_LIMIT
else
collection = @status['replies']

unless collection.nil? && @status.local?
ActivityPub::FetchRepliesService.new.call(
value_or_id(@status),
value_or_id(collection),
allow_synchronous_requests: true,
all_replies: true
)
unless @status.local?
json_status = fetch_resource(@status.uri, true, @current_account)

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

Expand Down
11 changes: 11 additions & 0 deletions app/services/activitypub/fetch_replies_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def call(parent_status, collection_or_uri, allow_synchronous_requests: true, req
@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 }] }
Expand All @@ -25,12 +28,20 @@ def call(parent_status, collection_or_uri, allow_synchronous_requests: true, req
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'])
Expand Down

0 comments on commit d478936

Please sign in to comment.