Merge branch 'profile-image-descriptions' into fork
This commit is contained in:
commit
8e8ec6bda9
4 changed files with 53 additions and 13 deletions
|
@ -440,6 +440,11 @@ def banner_url(user, options \\ []) do
|
|||
end
|
||||
end
|
||||
|
||||
def image_description(image, default \\ "")
|
||||
|
||||
def image_description(%{"name" => name}, _default), do: name
|
||||
def image_description(_, default), do: default
|
||||
|
||||
# Should probably be renamed or removed
|
||||
@spec ap_id(User.t()) :: String.t()
|
||||
def ap_id(%User{nickname: nickname}), do: "#{Endpoint.url()}/users/#{nickname}"
|
||||
|
|
|
@ -132,8 +132,22 @@ def render("user.json", %{user: user}) do
|
|||
"webfinger" => "acct:#{User.full_nickname(user)}",
|
||||
"vcard:Address" => user.location
|
||||
}
|
||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||
|> Map.merge(
|
||||
maybe_make_image(
|
||||
&User.avatar_url/2,
|
||||
User.image_description(user.avatar, nil),
|
||||
"icon",
|
||||
user
|
||||
)
|
||||
)
|
||||
|> Map.merge(
|
||||
maybe_make_image(
|
||||
&User.banner_url/2,
|
||||
User.image_description(user.banner, nil),
|
||||
"image",
|
||||
user
|
||||
)
|
||||
)
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
|
||||
|
@ -314,16 +328,24 @@ def collection(collection, iri, page, show_items \\ true, total \\ nil) do
|
|||
end
|
||||
end
|
||||
|
||||
defp maybe_make_image(func, key, user) do
|
||||
defp maybe_make_image(func, description, key, user) do
|
||||
if image = func.(user, no_default: true) do
|
||||
%{
|
||||
key => %{
|
||||
"type" => "Image",
|
||||
"url" => image
|
||||
}
|
||||
key =>
|
||||
%{
|
||||
"type" => "Image",
|
||||
"url" => image
|
||||
}
|
||||
|> maybe_put_description(description)
|
||||
}
|
||||
else
|
||||
%{}
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_put_description(map, description) when is_binary(description) do
|
||||
Map.put(map, "name", description)
|
||||
end
|
||||
|
||||
defp maybe_put_description(map, _description), do: map
|
||||
end
|
||||
|
|
|
@ -219,10 +219,10 @@ defp do_render("show.json", %{user: user} = opts) do
|
|||
|
||||
avatar = User.avatar_url(user) |> MediaProxy.url()
|
||||
avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(static: true)
|
||||
avatar_description = image_description(user.avatar)
|
||||
avatar_description = User.image_description(user.avatar)
|
||||
header = User.banner_url(user) |> MediaProxy.url()
|
||||
header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
|
||||
header_description = image_description(user.banner)
|
||||
header_description = User.image_description(user.banner)
|
||||
|
||||
following_count =
|
||||
if !user.hide_follows_count or !user.hide_follows or self,
|
||||
|
@ -352,10 +352,6 @@ defp username_from_nickname(string) when is_binary(string) do
|
|||
|
||||
defp username_from_nickname(_), do: nil
|
||||
|
||||
defp image_description(%{"name" => name}), do: name
|
||||
|
||||
defp image_description(_), do: ""
|
||||
|
||||
defp maybe_put_follow_requests_count(
|
||||
data,
|
||||
%User{id: user_id} = user,
|
||||
|
|
|
@ -68,6 +68,23 @@ test "Does not add an avatar image if the user hasn't set one" do
|
|||
result = UserView.render("user.json", %{user: user})
|
||||
assert result["icon"]["url"] == "https://someurl"
|
||||
assert result["image"]["url"] == "https://somebanner"
|
||||
|
||||
refute result["icon"]["name"]
|
||||
refute result["image"]["name"]
|
||||
end
|
||||
|
||||
test "Avatar has a description if the user set one" do
|
||||
user =
|
||||
insert(:user,
|
||||
avatar: %{
|
||||
"url" => [%{"href" => "https://someurl"}],
|
||||
"name" => "pleroma-tan using pleroma groups"
|
||||
}
|
||||
)
|
||||
|
||||
result = UserView.render("user.json", %{user: user})
|
||||
|
||||
assert result["icon"]["name"] == "pleroma-tan using pleroma groups"
|
||||
end
|
||||
|
||||
test "renders an invisible user with the invisible property set to true" do
|
||||
|
|
Loading…
Reference in a new issue