Object.Fetcher: Keep the with-do block as per kaniini proposition

This commit is contained in:
Haelwenn (lanodan) Monnier 2019-07-14 17:28:25 +02:00
parent a2c601acb5
commit 2592934480
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE

View file

@ -31,11 +31,10 @@ def fetch_object_from_id(id, options \\ []) do
{:ok, object} {:ok, object}
else else
Logger.info("Fetching #{id} via AP") Logger.info("Fetching #{id} via AP")
{status, data} = fetch_and_contain_remote_object_from_id(id)
object = Object.normalize(data, false)
if status == :ok and object == nil do with {:fetch, {:ok, data}} <- {:fetch, fetch_and_contain_remote_object_from_id(id)},
with params <- %{ {:normalize, nil} <- {:normalize, Object.normalize(data, false)},
params <- %{
"type" => "Create", "type" => "Create",
"to" => data["to"], "to" => data["to"],
"cc" => data["cc"], "cc" => data["cc"],
@ -43,31 +42,25 @@ def fetch_object_from_id(id, options \\ []) do
"actor" => data["actor"] || data["attributedTo"], "actor" => data["actor"] || data["attributedTo"],
"object" => data "object" => data
}, },
:ok <- Containment.contain_origin(id, params), {:containment, :ok} <- {:containment, Containment.contain_origin(id, params)},
{:ok, activity} <- Transmogrifier.handle_incoming(params, options), {:ok, activity} <- Transmogrifier.handle_incoming(params, options),
{:object, _data, %Object{} = object} <- {:object, _data, %Object{} = object} <-
{:object, data, Object.normalize(activity, false)} do {:object, data, Object.normalize(activity, false)} do
{:ok, object} {:ok, object}
else else
{:containment, _} ->
{:error, "Object containment failed."}
{:error, {:reject, nil}} -> {:error, {:reject, nil}} ->
{:reject, nil} {:reject, nil}
{:object, data, nil} -> {:object, data, nil} ->
reinject_object(data) reinject_object(data)
object = %Object{} -> {:normalize, object = %Object{}} ->
{:ok, object} {:ok, object}
:error -> _e ->
{:error, "Object containment failed."}
e ->
e
end
else
if status == :ok and object != nil do
{:ok, object}
else
# Only fallback when receiving a fetch/normalization error with ActivityPub # Only fallback when receiving a fetch/normalization error with ActivityPub
Logger.info("Couldn't get object via AP, trying out OStatus fetching...") Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
@ -79,7 +72,6 @@ def fetch_object_from_id(id, options \\ []) do
end end
end end
end end
end
def fetch_object_from_id!(id, options \\ []) do def fetch_object_from_id!(id, options \\ []) do
with {:ok, object} <- fetch_object_from_id(id, options) do with {:ok, object} <- fetch_object_from_id(id, options) do