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:
commit
a6fc97ffec
|
@ -0,0 +1 @@
|
||||||
|
ChatMessage: Tolerate attachment field set to an empty array
|
|
@ -57,6 +57,11 @@ def fix_attachment(%{"attachment" => [attachment | _]} = data) 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
|
||||||
|
|
|
@ -147,6 +147,21 @@ test "validates for a basic object with an attachment but without content", %{
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue