Move default mascot configuration to config/

This commit is contained in:
Sadposter 2019-05-20 16:12:55 +01:00
commit daeae8e2e7
No known key found for this signature in database
GPG key ID: 6F3BAD60DE190290
5 changed files with 46 additions and 15 deletions

View file

@ -1402,4 +1402,24 @@ defmodule Pleroma.User do
|> put_embed(:info, info_changeset)
|> update_and_set_cache()
end
def get_mascot(%{info: %{mascot: %{} = mascot}}) when not is_nil(mascot) do
mascot
end
def get_mascot(%{info: %{mascot: mascot}}) when is_nil(mascot) do
# use instance-default
config = Pleroma.Config.get([:assets, :mascots])
default_mascot = Pleroma.Config.get([:assets, :default_mascot])
mascot = Keyword.get(config, default_mascot)
%{
"id" => "default-mascot",
"url" => mascot[:url],
"preview_url" => mascot[:url],
"pleroma" => %{
"mime_type" => mascot[:mime_type]
}
}
end
end

View file

@ -43,19 +43,7 @@ defmodule Pleroma.User.Info do
field(:hide_favorites, :boolean, default: true)
field(:pinned_activities, {:array, :string}, default: [])
field(:flavour, :string, default: nil)
field(:mascot, :map,
default: %{
"id" => "pleromatan",
"url" => "/images/pleroma-fox-tan-smol.png",
"type" => "image",
"preview_url" => "/images/pleroma-fox-tan-smol.png",
"pleroma" => %{
"mime_type" => "image/png"
}
}
)
field(:mascot, :map, default: nil)
field(:emoji, {:array, :map}, default: [])
field(:notification_settings, :map,

View file

@ -736,7 +736,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def get_mascot(%{assigns: %{user: user}} = conn, _params) do
%{info: %{mascot: mascot}} = user
mascot = User.get_mascot(user)
conn
|> json(mascot)
@ -1364,7 +1364,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
display_sensitive_media: false,
reduce_motion: false,
max_toot_chars: limit,
mascot: Map.get(user.info.mascot, "url", "/images/pleroma-fox-tan-smol.png")
mascot: User.get_mascot(user)["url"]
},
rights: %{
delete_others_notice: present?(user.info.is_moderator),