commit: a6fc97ffecc7c48d46354c28af2275bafe4b7301
parent 3954dfd4f1881845a60f117a86ef96f3997c6c3c
Author: lain <lain@soykaf.club>
Date: Fri, 29 Dec 2023 08:12:27 +0000
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
Diffstat:
3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/changelog.d/chat-attachment-empty-array.fix b/changelog.d/chat-attachment-empty-array.fix
@@ -0,0 +1 @@
+ChatMessage: Tolerate attachment field set to an empty array
diff --git a/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex b/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
@@ -57,6 +57,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
|> Map.put("attachment", attachment)
end
+ def fix_attachment(%{"attachment" => attachment} = data) when attachment == [] do
+ data
+ |> Map.drop(["attachment"])
+ end
+
def fix_attachment(data), do: data
def changeset(struct, data) do
diff --git a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
@@ -147,6 +147,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
assert object["attachment"]
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", %{
valid_chat_message: valid_chat_message
} do