summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/user.ex46
-rw-r--r--lib/pleroma/web/api_spec/operations/account_operation.ex10
-rw-r--r--lib/pleroma/web/api_spec/operations/notification_operation.ex5
-rw-r--r--lib/pleroma/web/api_spec/schemas/account.ex6
-rw-r--r--lib/pleroma/web/api_spec/schemas/status.ex6
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex8
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex10
-rw-r--r--lib/pleroma/web/mastodon_api/views/notification_view.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex13
9 files changed, 98 insertions, 7 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index c6c536943..517009253 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -586,16 +586,26 @@ defmodule Pleroma.User do
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, min: 1, max: name_limit)
|> validate_inclusion(:actor_type, Pleroma.Constants.allowed_user_actor_types())
+ |> validate_image_description(:avatar_description, params)
+ |> validate_image_description(:header_description, params)
|> put_fields()
|> put_emoji()
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
- |> put_change_if_present(:avatar, &put_upload(&1, :avatar))
- |> put_change_if_present(:banner, &put_upload(&1, :banner))
+ |> put_change_if_present(
+ :avatar,
+ &put_upload(&1, :avatar, Map.get(params, :avatar_description))
+ )
+ |> put_change_if_present(
+ :banner,
+ &put_upload(&1, :banner, Map.get(params, :header_description))
+ )
|> put_change_if_present(:background, &put_upload(&1, :background))
|> put_change_if_present(
:pleroma_settings_store,
&{: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)
end
@@ -674,13 +684,41 @@ defmodule Pleroma.User do
end
end
- defp put_upload(value, type) do
+ defp put_upload(value, type, description \\ nil) do
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}
end
end
+ defp validate_image_description(changeset, key, params) do
+ description_limit = Config.get([:instance, :description_limit], 5_000)
+ description = Map.get(params, key)
+
+ if is_binary(description) and String.length(description) > description_limit do
+ changeset
+ |> add_error(key, "#{key} is too long")
+ else
+ changeset
+ end
+ end
+
+ defp maybe_update_image_description(changeset, image_field, description)
+ when is_binary(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
+ {:description_too_long, true} -> {:error}
+ _ -> changeset
+ end
+ end
+
+ defp maybe_update_image_description(changeset, _, _), do: changeset
+
def update_as_admin_changeset(struct, params) do
struct
|> update_changeset(params)
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
index d9614bc48..21a779dcb 100644
--- a/lib/pleroma/web/api_spec/operations/account_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -813,6 +813,16 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
allOf: [BooleanLike],
nullable: true,
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: %{
diff --git a/lib/pleroma/web/api_spec/operations/notification_operation.ex b/lib/pleroma/web/api_spec/operations/notification_operation.ex
index 2dc0f66df..94d1f6b82 100644
--- a/lib/pleroma/web/api_spec/operations/notification_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/notification_operation.ex
@@ -158,6 +158,10 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
type: :object,
properties: %{
id: %Schema{type: :string},
+ group_key: %Schema{
+ type: :string,
+ description: "Group key shared by similar notifications"
+ },
type: notification_type(),
created_at: %Schema{type: :string, format: :"date-time"},
account: %Schema{
@@ -180,6 +184,7 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
},
example: %{
"id" => "34975861",
+ "group-key" => "ungrouped-34975861",
"type" => "mention",
"created_at" => "2019-11-23T07:49:02.064Z",
"account" => Account.schema().example,
diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex
index 8aeb821a8..1f73ef60c 100644
--- a/lib/pleroma/web/api_spec/schemas/account.ex
+++ b/lib/pleroma/web/api_spec/schemas/account.ex
@@ -111,7 +111,9 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
format: :uri,
nullable: true,
description: "Favicon image of the user's instance"
- }
+ },
+ avatar_description: %Schema{type: :string},
+ header_description: %Schema{type: :string}
}
},
source: %Schema{
@@ -152,6 +154,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
example: %{
"acct" => "foobar",
"avatar" => "https://mypleroma.com/images/avi.png",
+ "avatar_description" => "",
"avatar_static" => "https://mypleroma.com/images/avi.png",
"bot" => false,
"created_at" => "2020-03-24T13:05:58.000Z",
@@ -162,6 +165,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"followers_count" => 0,
"following_count" => 1,
"header" => "https://mypleroma.com/images/banner.png",
+ "header_description" => "",
"header_static" => "https://mypleroma.com/images/banner.png",
"id" => "9tKi3esbG7OQgZ2920",
"locked" => false,
diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex
index 6e537b5da..25548d75b 100644
--- a/lib/pleroma/web/api_spec/schemas/status.ex
+++ b/lib/pleroma/web/api_spec/schemas/status.ex
@@ -249,6 +249,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
nullable: true,
description:
"A datetime (ISO 8601) that states when the post was pinned or `null` if the post is not pinned"
+ },
+ list_id: %Schema{
+ type: :integer,
+ nullable: true,
+ description:
+ "The ID of the list the post is addressed to (if any, only returned to author)"
}
}
},
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index 54d46c86b..68157b0c4 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -232,6 +232,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|> Maps.put_if_present(:is_discoverable, params[:discoverable])
|> Maps.put_if_present(:birthday, params[:birthday])
|> 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:
#
@@ -277,6 +279,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
{:error, %Ecto.Changeset{errors: [{:name, {_, _}} | _]}} ->
render_error(conn, :request_entity_too_large, "Name is too long")
+ {:error, %Ecto.Changeset{errors: [{:avatar_description, {_, _}} | _]}} ->
+ render_error(conn, :request_entity_too_large, "Avatar description is too long")
+
+ {:error, %Ecto.Changeset{errors: [{:header_description, {_, _}} | _]}} ->
+ render_error(conn, :request_entity_too_large, "Banner description is too long")
+
{:error, %Ecto.Changeset{errors: [{:fields, {"invalid", _}} | _]}} ->
render_error(conn, :request_entity_too_large, "One or more field entries are too long")
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 298c73986..7de6745d4 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -219,8 +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)
header = User.banner_url(user) |> MediaProxy.url()
header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
+ header_description = image_description(user.banner)
following_count =
if !user.hide_follows_count or !user.hide_follows or self,
@@ -321,7 +323,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
skip_thread_containment: user.skip_thread_containment,
background_image: image_url(user.background) |> MediaProxy.url(),
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])
@@ -345,6 +349,10 @@ 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,
diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex
index 3f2478719..c277af98b 100644
--- a/lib/pleroma/web/mastodon_api/views/notification_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex
@@ -95,6 +95,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
response = %{
id: to_string(notification.id),
+ group_key: "ungrouped-" <> to_string(notification.id),
type: notification.type,
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
account: account,
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 1b78477d0..3bf870c24 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -465,7 +465,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
parent_visible: visible_for_user?(reply_to, opts[:for]),
pinned_at: pinned_at,
quotes_count: object.data["quotesCount"] || 0,
- bookmark_folder: bookmark_folder
+ bookmark_folder: bookmark_folder,
+ list_id: get_list_id(object, client_posted_this_activity)
}
}
end
@@ -835,4 +836,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
nil
end
end
+
+ defp get_list_id(object, client_posted_this_activity) do
+ with true <- client_posted_this_activity,
+ %{data: %{"listMessage" => list_ap_id}} when is_binary(list_ap_id) <- object,
+ %{id: list_id} <- Pleroma.List.get_by_ap_id(list_ap_id) do
+ list_id
+ else
+ _ -> nil
+ end
+ end
end