about summary refs log tree commit diff
path: root/app/services/fetch_remote_status_service.rb
blob: 4f98b51f6ace0699d2112fc65d8f0fea5ad7cf4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class FetchRemoteStatusService < BaseService
  def call(url, prefetched_body = nil, on_behalf_of = nil)
    status = ActivityPub::TagManager.instance.uri_to_resource(url, Status)
    return status if status.present?

    if prefetched_body.nil?
      resource_url, resource_options = FetchResourceService.new.call(url, on_behalf_of: on_behalf_of)
    else
      resource_url     = url
      resource_options = { prefetched_body: prefetched_body }
    end

    return if resource_url.blank?

    resource_options ||= {}
    ActivityPub::FetchRemoteStatusService.new.call(resource_url, **resource_options.merge({ on_behalf_of: on_behalf_of }))
  end
end