Attempt to fix incorrect federation of default instance avatars

This commit is contained in:
Mark Felder 2019-03-25 18:47:04 -05:00
parent 15aa94f40f
commit 6f090f981b
3 changed files with 24 additions and 4 deletions

View File

@ -90,6 +90,14 @@ def avatar_url(user) do
end end
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 def banner_url(user) do
case user.info.banner do case user.info.banner do
%{"url" => [%{"href" => href} | _]} -> href %{"url" => [%{"href" => href} | _]} -> href

View File

@ -230,6 +230,21 @@ def update_object_in_activities(%{data: %{"id" => id}} = object) do
end) end)
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 #### Like-related helpers
@doc """ @doc """

View File

@ -87,16 +87,13 @@ def render("user.json", %{user: user}) do
"publicKeyPem" => public_key "publicKeyPem" => public_key
}, },
"endpoints" => endpoints, "endpoints" => endpoints,
"icon" => %{
"type" => "Image",
"url" => User.avatar_url(user)
},
"image" => %{ "image" => %{
"type" => "Image", "type" => "Image",
"url" => User.banner_url(user) "url" => User.banner_url(user)
}, },
"tag" => user.info.source_data["tag"] || [] "tag" => user.info.source_data["tag"] || []
} }
|> Map.merge(Utils.maybe_make_icon(user))
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end