rename outbox/pin fetching functions to be more generic

This commit is contained in:
TudbuT 2024-11-03 20:49:31 +01:00 committed by tudbut
parent c047a87d2e
commit 89588aecf5
3 changed files with 12 additions and 12 deletions

View file

@ -1587,7 +1587,7 @@ defp object_to_user_data(data, additional) do
actor_type = data["type"] || "Person"
featured_address = data["featured"]
{:ok, pinned_objects} = fetch_and_prepare_outbox_from_ap_id(featured_address)
{:ok, pinned_objects} = fetch_and_prepare_collection_from_ap_id(featured_address)
outbox_address = data["outbox"]
# first, check that the owner is correct
@ -1792,7 +1792,7 @@ def maybe_handle_clashing_nickname(data) do
end
end
def activity_data_from_outbox_collection(%{
def activity_data_from_collection(%{
"type" => "OrderedCollection",
"first" => first
}) do
@ -1807,7 +1807,7 @@ def activity_data_from_outbox_collection(%{
end
end
def activity_data_from_outbox_collection(
def activity_data_from_collection(
%{
"type" => type
} = collection
@ -1823,23 +1823,23 @@ def activity_data_from_outbox_collection(
end)
end
def activity_data_from_outbox_collection(obj) do
Logger.error("Could not parse outbox collection #{inspect(obj)}")
def activity_data_from_collection(obj) do
Logger.error("Could not parse collection #{inspect(obj)}")
%{}
end
def fetch_and_prepare_outbox_from_ap_id(nil) do
def fetch_and_prepare_collection_from_ap_id(nil) do
{:ok, %{}}
end
def fetch_and_prepare_outbox_from_ap_id(ap_id) do
Logger.info("Fetching outbox #{ap_id}")
def fetch_and_prepare_collection_from_ap_id(ap_id) do
Logger.info("Fetching collection #{ap_id}")
with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
{:ok, activity_data_from_outbox_collection(data)}
{:ok, activity_data_from_collection(data)}
else
e ->
Logger.error("Could not decode outbox collection at fetch #{ap_id}, #{inspect(e)}")
Logger.error("Could not decode collection at fetch #{ap_id}, #{inspect(e)}")
{:ok, %{}}
end
end

View file

@ -640,7 +640,7 @@ defp handle_incoming_normalised(
defp handle_incoming_normalised(%{"object" => o, "_akkoma_fake" => true}, options),
do: handle_incoming_normalised(o, options)
defp handle_incoming_normalised(o, _), do: :error
defp handle_incoming_normalised(_, _), do: :error
@spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil
def get_obj_helper(id, options \\ []) do

View file

@ -14,7 +14,7 @@ defmodule Pleroma.Workers.RemoteFetcherWorker do
@impl Oban.Worker
def perform(%Job{args: %{"op" => "fetch_outbox", "id" => address}}) do
with {:ok, outbox} <- ActivityPub.fetch_and_prepare_outbox_from_ap_id(address) do
with {:ok, outbox} <- ActivityPub.fetch_and_prepare_collection_from_ap_id(address) do
Enum.each(Enum.reverse(outbox), fn {ap_id, _} ->
if is_nil(Object.get_cached_by_ap_id(ap_id)) do
perform(%{