Merge branch 'profile-image-descriptions' into fork

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-09-15 12:09:18 +02:00
commit 00e253d3db
4 changed files with 43 additions and 5 deletions

View file

@ -1659,16 +1659,23 @@ defp get_actor_url(url) when is_list(url) do
defp get_actor_url(_url), do: nil defp get_actor_url(_url), do: nil
defp normalize_image(%{"url" => url}) do defp normalize_image(%{"url" => url} = data) do
%{ %{
"type" => "Image", "type" => "Image",
"url" => [%{"href" => url}] "url" => [%{"href" => url}]
} }
|> maybe_put_description(data)
end end
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image() defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
defp normalize_image(_), do: nil defp normalize_image(_), do: nil
defp maybe_put_description(map, %{"name" => description}) when is_binary(description) do
Map.put(map, "name", description)
end
defp maybe_put_description(map, _), do: map
defp object_to_user_data(data, additional) do defp object_to_user_data(data, additional) do
fields = fields =
data data

View file

@ -234,12 +234,14 @@ test "works for bridgy actors" do
assert user.avatar == %{ assert user.avatar == %{
"type" => "Image", "type" => "Image",
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}] "url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}],
"name" => "profile picture"
} }
assert user.banner == %{ assert user.banner == %{
"type" => "Image", "type" => "Image",
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}] "url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}],
"name" => "profile picture"
} }
end end
@ -454,6 +456,35 @@ test "fetches user location information from misskey" do
assert user.location == "Poland" assert user.location == "Poland"
end end
test "fetches avatar description" do
user_id = "https://example.com/users/marcin"
user_data =
"test/fixtures/users_mock/user.json"
|> File.read!()
|> String.replace("{{nickname}}", "marcin")
|> Jason.decode!()
|> Map.delete("featured")
|> Map.update("icon", %{}, fn image -> Map.put(image, "name", "image description") end)
|> Jason.encode!()
Tesla.Mock.mock(fn
%{
method: :get,
url: ^user_id
} ->
%Tesla.Env{
status: 200,
body: user_data,
headers: [{"content-type", "application/activity+json"}]
}
end)
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
assert user.avatar["name"] == "image description"
end
end end
test "it fetches the appropriate tag-restricted posts" do test "it fetches the appropriate tag-restricted posts" do

View file

@ -78,13 +78,13 @@ test "Avatar has a description if the user set one" do
insert(:user, insert(:user,
avatar: %{ avatar: %{
"url" => [%{"href" => "https://someurl"}], "url" => [%{"href" => "https://someurl"}],
"name" => "pleroma-tan using pleroma groups" "name" => "a drawing of pleroma-tan using pleroma groups"
} }
) )
result = UserView.render("user.json", %{user: user}) result = UserView.render("user.json", %{user: user})
assert result["icon"]["name"] == "pleroma-tan using pleroma groups" assert result["icon"]["name"] == "a drawing of pleroma-tan using pleroma groups"
end end
test "renders an invisible user with the invisible property set to true" do test "renders an invisible user with the invisible property set to true" do