From 6f090f981b26274c87b9df88e1bcb2719f46814b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 25 Mar 2019 18:47:04 -0500 Subject: [PATCH] Attempt to fix incorrect federation of default instance avatars --- lib/pleroma/user.ex | 8 ++++++++ lib/pleroma/web/activity_pub/utils.ex | 15 +++++++++++++++ lib/pleroma/web/activity_pub/views/user_view.ex | 5 +---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 41289b4d0..ee5eb8efa 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -90,6 +90,14 @@ defmodule Pleroma.User do end end + # Do not return instance default avatar for federation + def avatar_url_ap(user) do + case user.avatar do + %{"url" => [%{"href" => href} | _]} -> href + _ -> nil + end + end + def banner_url(user) do case user.info.banner do %{"url" => [%{"href" => href} | _]} -> href diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 2e9ffe41c..6d74738f0 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -230,6 +230,21 @@ defmodule Pleroma.Web.ActivityPub.Utils do end) end + # Only federate user icon if not nil + # Prevents federating instance default avatars + def maybe_make_icon(user) do + if User.avatar_url_ap(user) do + %{ + "icon" => %{ + "type" => "Image", + "url" => User.avatar_url_ap(user) + } + } + else + [] + end + end + #### Like-related helpers @doc """ diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 3d00dcbf2..f5c86d360 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -87,16 +87,13 @@ defmodule Pleroma.Web.ActivityPub.UserView do "publicKeyPem" => public_key }, "endpoints" => endpoints, - "icon" => %{ - "type" => "Image", - "url" => User.avatar_url(user) - }, "image" => %{ "type" => "Image", "url" => User.banner_url(user) }, "tag" => user.info.source_data["tag"] || [] } + |> Map.merge(Utils.maybe_make_icon(user)) |> Map.merge(Utils.make_json_ld_header()) end