mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-31 12:28:43 +00:00
Allow providing avatar/header descriptions
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
fcf9ad5573
commit
71ef9f9519
4 changed files with 45 additions and 5 deletions
|
@ -589,13 +589,21 @@ defmodule Pleroma.User do
|
||||||
|> put_fields()
|
|> put_fields()
|
||||||
|> put_emoji()
|
|> put_emoji()
|
||||||
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
||||||
|> put_change_if_present(:avatar, &put_upload(&1, :avatar))
|
|> put_change_if_present(
|
||||||
|> put_change_if_present(:banner, &put_upload(&1, :banner))
|
:avatar,
|
||||||
|
&put_upload(&1, :avatar, Map.get(params, :avatar_description, nil))
|
||||||
|
)
|
||||||
|
|> put_change_if_present(
|
||||||
|
:banner,
|
||||||
|
&put_upload(&1, :banner, Map.get(params, :header_description, nil))
|
||||||
|
)
|
||||||
|> put_change_if_present(:background, &put_upload(&1, :background))
|
|> put_change_if_present(:background, &put_upload(&1, :background))
|
||||||
|> put_change_if_present(
|
|> put_change_if_present(
|
||||||
:pleroma_settings_store,
|
:pleroma_settings_store,
|
||||||
&{:ok, Map.merge(struct.pleroma_settings_store, &1)}
|
&{:ok, Map.merge(struct.pleroma_settings_store, &1)}
|
||||||
)
|
)
|
||||||
|
|> maybe_update_image_description(:avatar, Map.get(params, :avatar_description))
|
||||||
|
|> maybe_update_image_description(:banner, Map.get(params, :header_description))
|
||||||
|> validate_fields(false)
|
|> validate_fields(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -674,13 +682,25 @@ defmodule Pleroma.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_upload(value, type) do
|
defp put_upload(value, type, description \\ nil) do
|
||||||
with %Plug.Upload{} <- value,
|
with %Plug.Upload{} <- value,
|
||||||
{:ok, object} <- ActivityPub.upload(value, type: type) do
|
{:ok, object} <- ActivityPub.upload(value, type: type, description: description) do
|
||||||
{:ok, object.data}
|
{:ok, object.data}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_update_image_description(changeset, image_field, description) do
|
||||||
|
with {:image_missing, true} <- {:image_missing, not changed?(changeset, image_field)},
|
||||||
|
{:existing_image, %{"id" => id}} <-
|
||||||
|
{:existing_image, Map.get(changeset.data, image_field)},
|
||||||
|
{:object, %Object{} = object} <- {:object, Object.get_by_ap_id(id)},
|
||||||
|
{:ok, object} <- Object.update_data(object, %{"name" => description}) do
|
||||||
|
put_change(changeset, image_field, object.data)
|
||||||
|
else
|
||||||
|
e -> changeset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_as_admin_changeset(struct, params) do
|
def update_as_admin_changeset(struct, params) do
|
||||||
struct
|
struct
|
||||||
|> update_changeset(params)
|
|> update_changeset(params)
|
||||||
|
|
|
@ -813,6 +813,16 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
||||||
allOf: [BooleanLike],
|
allOf: [BooleanLike],
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: "User's birthday will be visible"
|
description: "User's birthday will be visible"
|
||||||
|
},
|
||||||
|
avatar_description: %Schema{
|
||||||
|
type: :string,
|
||||||
|
nullable: true,
|
||||||
|
description: "Avatar image description."
|
||||||
|
},
|
||||||
|
header_description: %Schema{
|
||||||
|
type: :string,
|
||||||
|
nullable: true,
|
||||||
|
description: "Header image description."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
example: %{
|
example: %{
|
||||||
|
|
|
@ -232,6 +232,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
||||||
|> Maps.put_if_present(:is_discoverable, params[:discoverable])
|
|> Maps.put_if_present(:is_discoverable, params[:discoverable])
|
||||||
|> Maps.put_if_present(:birthday, params[:birthday])
|
|> Maps.put_if_present(:birthday, params[:birthday])
|
||||||
|> Maps.put_if_present(:language, Pleroma.Web.Gettext.normalize_locale(params[:language]))
|
|> Maps.put_if_present(:language, Pleroma.Web.Gettext.normalize_locale(params[:language]))
|
||||||
|
|> Maps.put_if_present(:avatar_description, params[:avatar_description])
|
||||||
|
|> Maps.put_if_present(:header_description, params[:header_description])
|
||||||
|
|
||||||
# What happens here:
|
# What happens here:
|
||||||
#
|
#
|
||||||
|
|
|
@ -220,8 +220,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
|
|
||||||
avatar = User.avatar_url(user) |> MediaProxy.url()
|
avatar = User.avatar_url(user) |> MediaProxy.url()
|
||||||
avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(static: true)
|
avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(static: true)
|
||||||
|
avatar_description = image_description(user.avatar)
|
||||||
header = User.banner_url(user) |> MediaProxy.url()
|
header = User.banner_url(user) |> MediaProxy.url()
|
||||||
header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
|
header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
|
||||||
|
header_description = image_description(user.banner)
|
||||||
|
|
||||||
following_count =
|
following_count =
|
||||||
if !user.hide_follows_count or !user.hide_follows or self,
|
if !user.hide_follows_count or !user.hide_follows or self,
|
||||||
|
@ -323,7 +325,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||||
accepts_chat_messages: user.accepts_chat_messages,
|
accepts_chat_messages: user.accepts_chat_messages,
|
||||||
favicon: favicon
|
favicon: favicon
|
||||||
}
|
},
|
||||||
|
avatar_description: avatar_description,
|
||||||
|
header_description: header_description
|
||||||
}
|
}
|
||||||
|> maybe_put_role(user, opts[:for])
|
|> maybe_put_role(user, opts[:for])
|
||||||
|> maybe_put_settings(user, opts[:for], opts)
|
|> maybe_put_settings(user, opts[:for], opts)
|
||||||
|
@ -346,6 +350,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
|
|
||||||
defp username_from_nickname(_), do: nil
|
defp username_from_nickname(_), do: nil
|
||||||
|
|
||||||
|
defp image_description(%{"name" => name}), do: name
|
||||||
|
|
||||||
|
defp image_description(_), do: ""
|
||||||
|
|
||||||
defp maybe_put_follow_requests_count(
|
defp maybe_put_follow_requests_count(
|
||||||
data,
|
data,
|
||||||
%User{id: user_id} = user,
|
%User{id: user_id} = user,
|
||||||
|
|
Loading…
Reference in a new issue