Object.Fetcher: Fallback to OStatus only if AP actually fails

This commit is contained in:
Haelwenn (lanodan) Monnier 2019-07-14 12:13:11 +02:00
parent 40d0a198e2
commit e1c08a67d6
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE

View file

@ -31,14 +31,15 @@ def fetch_object_from_id(id, options \\ []) do
{:ok, object}
else
Logger.info("Fetching #{id} via AP")
{status, data} = fetch_and_contain_remote_object_from_id(id)
object = Object.normalize(data, false)
with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
nil <- Object.normalize(data, false),
params <- %{
if status == :ok and object == nil do
with params <- %{
"type" => "Create",
"to" => data["to"],
"cc" => data["cc"],
# TODO: Should we seriously keep this attributedTo thing?
# Should we seriously keep this attributedTo thing?
"actor" => data["actor"] || data["attributedTo"],
"object" => data
},
@ -60,9 +61,17 @@ def fetch_object_from_id(id, options \\ []) do
:error ->
{:error, "Object containment failed."}
_e ->
e ->
e
end
else
if status == :ok and object != nil do
{:ok, object}
else
# Only fallback when receiving a fetch/normalization error with ActivityPub
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
# FIXME: OStatus Object Containment?
case OStatus.fetch_activity_from_url(id) do
{:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
e -> e
@ -70,6 +79,7 @@ def fetch_object_from_id(id, options \\ []) do
end
end
end
end
def fetch_object_from_id!(id, options \\ []) do
with {:ok, object} <- fetch_object_from_id(id, options) do