From 7c5f8b24311253ef89c7e47cd7ce22ebe6cf2ec9 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 29 Jun 2023 18:57:42 +0200 Subject: [PATCH] fix(federation): fix getting pictures from Gruppe actors They directly put urls for icon/image properties Signed-off-by: Thomas Citharel --- .../activity_stream/converter/actor.ex | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/federation/activity_stream/converter/actor.ex b/lib/federation/activity_stream/converter/actor.ex index 9c5cf9472..db9a4b91a 100644 --- a/lib/federation/activity_stream/converter/actor.ex +++ b/lib/federation/activity_stream/converter/actor.ex @@ -36,10 +36,18 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do @spec as_to_model_data(map()) :: map() | {:error, :actor_not_allowed_type} def as_to_model_data(%{"type" => type} = data) when type in @allowed_types do avatar = - download_picture(get_in(data, ["icon", "url"]), get_in(data, ["icon", "name"]), "avatar") + download_picture( + get_picture(data, ["icon", "url"]), + get_picture(data, ["icon", "name"]), + "avatar" + ) banner = - download_picture(get_in(data, ["image", "url"]), get_in(data, ["image", "name"]), "banner") + download_picture( + get_picture(data, ["image", "url"]), + get_picture(data, ["image", "name"]), + "banner" + ) address = get_address(data["location"]) @@ -193,4 +201,10 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do end defp maybe_add_physical_address(res, _), do: res + + defp get_picture(nil, _keys), do: nil + defp get_picture(url, _keys) when is_binary(url), do: url + + defp get_picture(data, [key | rest] = keys) when is_map(data) and is_list(keys), + do: get_picture(data[key], rest) end