Fix paged featured collection fetches
This commit is contained in:
parent
093b156c65
commit
b054c2aa42
3 changed files with 168 additions and 2 deletions
|
|
@ -1881,11 +1881,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
@featured_collection_types ["OrderedCollection", "Collection"]
|
||||
@featured_collection_page_types ["OrderedCollectionPage", "CollectionPage"]
|
||||
@featured_collection_item_types @featured_collection_types ++ @featured_collection_page_types
|
||||
|
||||
def pin_data_from_featured_collection(%{
|
||||
"type" => type,
|
||||
"orderedItems" => objects
|
||||
})
|
||||
when type in ["OrderedCollection", "Collection"] do
|
||||
when type in @featured_collection_item_types do
|
||||
Map.new(objects, fn
|
||||
%{"id" => object_ap_id} -> {object_ap_id, NaiveDateTime.utc_now()}
|
||||
object_ap_id when is_binary(object_ap_id) -> {object_ap_id, NaiveDateTime.utc_now()}
|
||||
|
|
@ -1903,7 +1907,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
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)}
|
||||
{:ok, prepare_featured_collection(data)}
|
||||
else
|
||||
e ->
|
||||
Logger.error("Could not decode featured collection at fetch #{ap_id}, #{inspect(e)}")
|
||||
|
|
@ -1911,6 +1915,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
defp prepare_featured_collection(%{"orderedItems" => objects} = data) when is_list(objects) do
|
||||
pin_data_from_featured_collection(data)
|
||||
end
|
||||
|
||||
defp prepare_featured_collection(%{
|
||||
"type" => type,
|
||||
"first" => %{"type" => page_type} = first
|
||||
})
|
||||
when type in @featured_collection_types and page_type in @featured_collection_page_types do
|
||||
pin_data_from_featured_collection(first)
|
||||
end
|
||||
|
||||
defp prepare_featured_collection(%{"type" => type, "first" => first})
|
||||
when type in @featured_collection_types and is_binary(first) do
|
||||
case Fetcher.fetch_and_contain_remote_object_from_id(first) do
|
||||
{:ok, data} ->
|
||||
pin_data_from_featured_collection(data)
|
||||
|
||||
e ->
|
||||
Logger.error("Could not decode featured collection page at fetch #{first}, #{inspect(e)}")
|
||||
%{}
|
||||
end
|
||||
end
|
||||
|
||||
defp prepare_featured_collection(data) do
|
||||
pin_data_from_featured_collection(data)
|
||||
end
|
||||
|
||||
def enqueue_pin_fetches(%{pinned_objects: pins}) do
|
||||
# enqueue a task to fetch all pinned objects
|
||||
Enum.each(pins, fn {ap_id, _} ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue