Merge branch 'fix/ap-icon' into 'develop'
Do not federate instance avatar Closes #759 See merge request pleroma/pleroma!977
This commit is contained in:
commit
ff3b09f6b3
@ -79,17 +79,17 @@ defmodule Pleroma.User do
|
||||
def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true
|
||||
def superuser?(_), do: false
|
||||
|
||||
def avatar_url(user) do
|
||||
def avatar_url(user, options \\ []) do
|
||||
case user.avatar do
|
||||
%{"url" => [%{"href" => href} | _]} -> href
|
||||
_ -> "#{Web.base_url()}/images/avi.png"
|
||||
_ -> !options[:no_default] && "#{Web.base_url()}/images/avi.png"
|
||||
end
|
||||
end
|
||||
|
||||
def banner_url(user) do
|
||||
def banner_url(user, options \\ []) do
|
||||
case user.info.banner do
|
||||
%{"url" => [%{"href" => href} | _]} -> href
|
||||
_ -> "#{Web.base_url()}/images/banner.png"
|
||||
_ -> !options[:no_default] && "#{Web.base_url()}/images/banner.png"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,16 +87,10 @@ 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(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
|
||||
@ -294,4 +288,17 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
||||
map
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_make_image(func, key, user) do
|
||||
if image = func.(user, no_default: true) do
|
||||
%{
|
||||
key => %{
|
||||
"type" => "Image",
|
||||
"url" => image
|
||||
}
|
||||
}
|
||||
else
|
||||
%{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,6 +16,29 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
||||
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
||||
end
|
||||
|
||||
test "Does not add an avatar image if the user hasn't set one" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
||||
|
||||
result = UserView.render("user.json", %{user: user})
|
||||
refute result["icon"]
|
||||
refute result["image"]
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
avatar: %{"url" => [%{"href" => "https://someurl"}]},
|
||||
info: %{
|
||||
banner: %{"url" => [%{"href" => "https://somebanner"}]}
|
||||
}
|
||||
)
|
||||
|
||||
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
||||
|
||||
result = UserView.render("user.json", %{user: user})
|
||||
assert result["icon"]["url"] == "https://someurl"
|
||||
assert result["image"]["url"] == "https://somebanner"
|
||||
end
|
||||
|
||||
describe "endpoints" do
|
||||
test "local users have a usable endpoints structure" do
|
||||
user = insert(:user)
|
||||
|
Loading…
Reference in New Issue
Block a user