summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-07-14 17:28:25 +0200
committerAriadne Conill <ariadne@dereferenced.org>2019-07-14 19:30:39 +0000
commit48927b1d3bcfd789a9bb44ffd18f5b56f887cecb (patch)
treeed5c8144daac76d408cd5810b1533fc0d0244884
parent1c79ec2c086e0c1e24c6c58861c6debbb950835e (diff)
Object.Fetcher: Keep the with-do block as per kaniini proposition
-rw-r--r--lib/pleroma/object/fetcher.ex58
1 files changed, 25 insertions, 33 deletions
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index 91c4c1090..6404a3a95 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -27,43 +27,36 @@ defmodule Pleroma.Object.Fetcher 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)
- if status == :ok and object == nil do
- with params <- %{
- "type" => "Create",
- "to" => data["to"],
- "cc" => data["cc"],
- # Should we seriously keep this attributedTo thing?
- "actor" => data["actor"] || data["attributedTo"],
- "object" => data
- },
- :ok <- Containment.contain_origin(id, params),
- {:ok, activity} <- Transmogrifier.handle_incoming(params, options),
- {:object, _data, %Object{} = object} <-
- {:object, data, Object.normalize(activity, false)} do
- {:ok, object}
- else
- {:error, {:reject, nil}} ->
- {:reject, nil}
-
- {:object, data, nil} ->
- reinject_object(data)
+ with {:fetch, {:ok, data}} <- {:fetch, fetch_and_contain_remote_object_from_id(id)},
+ {:normalize, nil} <- {:normalize, Object.normalize(data, false)},
+ params <- %{
+ "type" => "Create",
+ "to" => data["to"],
+ "cc" => data["cc"],
+ # Should we seriously keep this attributedTo thing?
+ "actor" => data["actor"] || data["attributedTo"],
+ "object" => data
+ },
+ {:containment, :ok} <- {:containment, Containment.contain_origin(id, params)},
+ {:ok, activity} <- Transmogrifier.handle_incoming(params, options),
+ {:object, _data, %Object{} = object} <-
+ {:object, data, Object.normalize(activity, false)} do
+ {:ok, object}
+ else
+ {:containment, _} ->
+ {:error, "Object containment failed."}
- object = %Object{} ->
- {:ok, object}
+ {:error, {:reject, nil}} ->
+ {:reject, nil}
- :error ->
- {:error, "Object containment failed."}
+ {:object, data, nil} ->
+ reinject_object(data)
- e ->
- e
- end
- else
- if status == :ok and object != nil do
+ {:normalize, object = %Object{}} ->
{:ok, object}
- else
+
+ _e ->
# Only fallback when receiving a fetch/normalization error with ActivityPub
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
@@ -72,7 +65,6 @@ defmodule Pleroma.Object.Fetcher do
{:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
e -> e
end
- end
end
end
end