summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1batross <a1ba.omarov@gmail.com>2022-04-25 00:48:11 +0200
committerAlibek Omarov <a1ba.omarov@gmail.com>2022-04-25 02:13:32 +0300
commit7e43e712347a29bbc5874587785636943101f64e (patch)
tree64185e5155c5a25ab8d3194cacc39439410d0233
parentd91e9cee04f2e4cb809037e4fcfebc295994b563 (diff)
activity_pub: fix case when featured collection misses orderedItems fieldfix/featured-collection-without-orderedItems-property
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index e6475a2b7..bc8074a57 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1673,15 +1673,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
- def pin_data_from_featured_collection(%{
- "type" => type,
- "orderedItems" => objects
- })
+ def pin_data_from_featured_collection(ap_id, %{"type" => type} = data)
when type in ["OrderedCollection", "Collection"] 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()}
- end)
+ objects = Map.get(data, "orderedItems", nil)
+
+ if is_list(objects) 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()}
+ end)
+ else
+ Logger.error("Could not decode featured collection at #{ap_id}, #{inspect(data)}")
+ %{}
+ end
end
def fetch_and_prepare_featured_from_ap_id(nil) do
@@ -1690,7 +1694,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, pin_data_from_featured_collection(ap_id, data)}
else
e ->
Logger.error("Could not decode featured collection at fetch #{ap_id}, #{inspect(e)}")