|> Map.put(:bio, HTML.filter_tags(user.bio, filter))
|> Map.put(:fields, fields)
end
+
+ def get_cached_favicon(%User{} = user) do
+ key = "favicon:#{user.ap_id}"
+ Cachex.fetch!(:user_cache, key, fn _ -> get_favicon(user) end)
+ end
+
+ def get_cached_favicon(_user) do
+ nil
+ end
+
+ def get_favicon(user) do
+ try do
+ with url <- user.ap_id,
+ true <- is_binary(url),
+ {:ok, %Tesla.Env{body: html}} <- Pleroma.HTTP.get(url),
+ favicon_rel <-
+ html
+ |> Floki.parse_document!()
+ |> Floki.attribute("link[rel=icon]", "href")
+ |> List.first(),
+ favicon_url <- URI.merge(URI.parse(url), favicon_rel) |> to_string(),
+ true <- is_binary(favicon_url) do
+ favicon_url
+ else
+ _ -> nil
+ end
+ rescue
+ _ -> nil
+ end
+ end
end
hide_favorites: user.hide_favorites,
relationship: relationship,
skip_thread_containment: user.skip_thread_containment,
- background_image: image_url(user.background) |> MediaProxy.url()
+ background_image: image_url(user.background) |> MediaProxy.url(),
+ favicon: User.get_cached_favicon(user) |> MediaProxy.url()
}
}
|> maybe_put_role(user, opts[:for])
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/relay/relay.json")}}
end
+ def get("http://localhost:4001/users/" <> _, _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/7369654.html")}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
pleroma: %{
ap_id: user.ap_id,
background_image: "https://example.com/images/asuka_hospital.png",
+ favicon: nil,
confirmation_pending: false,
tags: [],
is_admin: false,
pleroma: %{
ap_id: user.ap_id,
background_image: nil,
+ favicon: nil,
confirmation_pending: false,
tags: [],
is_admin: false,