diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index e6548a818..bf766699d 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1662,6 +1662,36 @@ def maybe_handle_clashing_nickname(data) do end end + 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" => "Collection", + "first" => first + }) do + with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(first) do + page + |> Map.get("items") + |> 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, "orderedItems" => objects diff --git a/test/fixtures/friendica/friendica_featured_collection_first.json b/test/fixtures/friendica/friendica_featured_collection_first.json index 7d450e42f..1f9dce420 100644 --- a/test/fixtures/friendica/friendica_featured_collection_first.json +++ b/test/fixtures/friendica/friendica_featured_collection_first.json @@ -26,5 +26,9 @@ "type": "OrderedCollectionPage", "totalItems": 0, "partOf": "https://friendica.example.com/featured/raha", - "orderedItems": [] + "orderedItems": [ + { + "id": "http://inserted" + } + ] } diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index b21b9ee28..2b65f59e0 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -315,16 +315,15 @@ test "fetches user featured collection" do end test "fetches user featured collection using the first property" do - ap_id = "https://friendica.example.com/raha" featured_url = "https://friendica.example.com/raha/collections/featured" - first_url = "https://friendica.mnementh.co.uk/featured/spyro?page=1" + first_url = "https://friendica.example.com/featured/raha?page=1" featured_data = "test/fixtures/friendica/friendica_featured_collection.json" |> File.read!() page_data = - "test/fixtures/friendica/friendica_featured_collection.json" + "test/fixtures/friendica/friendica_featured_collection_first.json" |> File.read!() Tesla.Mock.mock(fn @@ -337,9 +336,7 @@ test "fetches user featured collection using the first property" do body: featured_data, headers: [{"content-type", "application/activity+json"}] } - end) - Tesla.Mock.mock_global(fn %{ method: :get, url: ^first_url @@ -352,6 +349,7 @@ test "fetches user featured collection using the first property" do end) {:ok, data} = ActivityPub.fetch_and_prepare_featured_from_ap_id(featured_url) + assert Map.has_key?(data, "http://inserted") end test "it fetches the appropriate tag-restricted posts" do