+ def pin_data_from_featured_collection(%{
+ "type" => "OrderedCollection",
+ "first" => first
+ }) do
+ with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(first) do
+ page
+ |> Map.get("orderedItems")
+ |> Map.new(fn %{"id" => object_ap_id} -> {object_ap_id, NaiveDateTime.utc_now()} end)
+ else
+ e ->
+ Logger.error("Could not decode featured collection at fetch #{first}, #{inspect(e)}")
+ {:ok, %{}}
+ end
+ end
+
+ def pin_data_from_featured_collection(
+ %{
+ "type" => type
+ } = collection
+ )
+ when type in ["OrderedCollection", "Collection"] do
+ {:ok, objects} = Collections.Fetcher.fetch_collection(collection)
+
+ # Items can either be a map _or_ a string
+ objects
+ |> Map.new(fn
+ ap_id when is_binary(ap_id) -> {ap_id, NaiveDateTime.utc_now()}
+ %{"id" => object_ap_id} -> {object_ap_id, NaiveDateTime.utc_now()}
+ end)
+ end
+
+ def fetch_and_prepare_featured_from_ap_id(nil) do
+ {:ok, %{}}
+ end
+
+ def fetch_and_prepare_featured_from_ap_id(ap_id) do
+ with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
+ {:ok, pin_data_from_featured_collection(data)}
+ else
+ e ->
+ Logger.error("Could not decode featured collection at fetch #{ap_id}, #{inspect(e)}")
+ {:ok, %{}}
+ end
+ end
+
+ def pinned_fetch_task(nil), do: nil
+
+ def pinned_fetch_task(%{pinned_objects: pins}) do
+ if Enum.all?(pins, fn {ap_id, _} ->
+ Object.get_cached_by_ap_id(ap_id) ||
+ match?({:ok, _object}, Fetcher.fetch_object_from_id(ap_id))
+ end) do
+ :ok
+ else
+ :error
+ end
+ end
+
+ def make_user_from_ap_id(ap_id, additional \\ []) do