diff options
| author | marcin mikołajczak <git@mkljczk.pl> | 2024-09-14 20:17:08 +0200 | 
|---|---|---|
| committer | marcin mikołajczak <git@mkljczk.pl> | 2024-09-14 21:32:32 +0200 | 
| commit | 1a120d013019fc15b3f440f7db71d3eb328bc798 (patch) | |
| tree | a96f688e973bb8385460fbe4ba3bbd62802ae31b /lib | |
| parent | c1a1150888f48448d353897327d4d3f050bec9b4 (diff) | |
| download | pleroma-1a120d013019fc15b3f440f7db71d3eb328bc798.tar.gz pleroma-1a120d013019fc15b3f440f7db71d3eb328bc798.zip | |
Federate avatar/header descriptions
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/user.ex | 5 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 9 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/views/user_view.ex | 36 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/views/account_view.ex | 8 | 
4 files changed, 44 insertions, 14 deletions
| diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 517009253..7a36ece77 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -419,6 +419,11 @@ defmodule Pleroma.User 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}" diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index a2a94a0ff..df8795fe4 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1542,16 +1542,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do    defp get_actor_url(_url), do: nil -  defp normalize_image(%{"url" => url}) do +  defp normalize_image(%{"url" => url} = data) do      %{        "type" => "Image",        "url" => [%{"href" => url}]      } +    |> maybe_put_description(data)    end    defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()    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      fields =        data diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 937e4fd67..cd485ed64 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -129,8 +129,22 @@ defmodule Pleroma.Web.ActivityPub.UserView do        "vcard:bday" => birthday,        "webfinger" => "acct:#{User.full_nickname(user)}"      } -    |> 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 @@ -305,16 +319,24 @@ defmodule Pleroma.Web.ActivityPub.UserView 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 diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 7de6745d4..f6727d29d 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -219,10 +219,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView 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, @@ -349,10 +349,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView 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, | 
