+ # For Undos that don't have the complete object attached, try to find it in our database.
+ def handle_incoming(
+ %{
+ "type" => "Undo",
+ "object" => object
+ } = activity,
+ options
+ )
+ when is_binary(object) do
+ with %Activity{data: data} <- Activity.get_by_ap_id(object) do
+ activity
+ |> Map.put("object", data)
+ |> handle_incoming(options)
+ else
+ _e -> :error
+ end
+ end
+
+ def handle_incoming(_, _), do: :error
+
+ @spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil
+ def get_obj_helper(id, options \\ []) do
+ case Object.normalize(id, true, options) do
+ %Object{} = object -> {:ok, object}
+ _ -> nil
+ end
+ end
+
+ @spec get_embedded_obj_helper(String.t() | Object.t(), User.t()) :: {:ok, Object.t()} | nil
+ def get_embedded_obj_helper(%{"attributedTo" => attributed_to, "id" => object_id} = data, %User{
+ ap_id: ap_id
+ })
+ when attributed_to == ap_id do
+ with {:ok, activity} <-
+ handle_incoming(%{
+ "type" => "Create",
+ "to" => data["to"],
+ "cc" => data["cc"],
+ "actor" => attributed_to,
+ "object" => data
+ }) do
+ {:ok, Object.normalize(activity)}
+ else
+ _ -> get_obj_helper(object_id)
+ end
+ end