Merge branch 'bugfix/chat-attachment-empty-array' into 'develop'

ChatMessage: Tolerate attachment field set to an empty array

Closes #3224

See merge request pleroma/pleroma!4020
This commit is contained in:
lain 2023-12-29 08:12:27 +00:00
commit a6fc97ffec
3 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1 @@
ChatMessage: Tolerate attachment field set to an empty array

View File

@ -57,6 +57,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
|> Map.put("attachment", attachment) |> Map.put("attachment", attachment)
end end
def fix_attachment(%{"attachment" => attachment} = data) when attachment == [] do
data
|> Map.drop(["attachment"])
end
def fix_attachment(data), do: data def fix_attachment(data), do: data
def changeset(struct, data) do def changeset(struct, data) do

View File

@ -147,6 +147,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
assert object["attachment"] assert object["attachment"]
end end
test "validates for a basic object with content but attachment set to empty array", %{
user: user,
recipient: recipient
} do
{:ok, valid_chat_message, _} = Builder.chat_message(user, recipient.ap_id, "Hello!")
valid_chat_message =
valid_chat_message
|> Map.put("attachment", [])
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
assert object == Map.drop(valid_chat_message, ["attachment"])
end
test "does not validate if the message has no content", %{ test "does not validate if the message has no content", %{
valid_chat_message: valid_chat_message valid_chat_message: valid_chat_message
} do } do