forked from AkkomaGang/akkoma
ChatMessageValidator: Allow one message in an array, too.
This commit is contained in:
parent
0d417e005d
commit
be4db41d71
2 changed files with 44 additions and 0 deletions
|
@ -47,9 +47,18 @@ def cast_data(data) do
|
||||||
def fix(data) do
|
def fix(data) do
|
||||||
data
|
data
|
||||||
|> fix_emoji()
|
|> fix_emoji()
|
||||||
|
|> fix_attachment()
|
||||||
|> Map.put_new("actor", data["attributedTo"])
|
|> Map.put_new("actor", data["attributedTo"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Throws everything but the first one away
|
||||||
|
def fix_attachment(%{"attachment" => [attachment | _]} = data) do
|
||||||
|
data
|
||||||
|
|> Map.put("attachment", attachment)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_attachment(data), do: data
|
||||||
|
|
||||||
def changeset(struct, data) do
|
def changeset(struct, data) do
|
||||||
data = fix(data)
|
data = fix(data)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "attachments" do
|
describe "attachments" do
|
||||||
|
test "works with honkerific attachments" do
|
||||||
|
attachment = %{
|
||||||
|
"mediaType" => "image/jpeg",
|
||||||
|
"name" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||||
|
"summary" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||||
|
"type" => "Document",
|
||||||
|
"url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, attachment} =
|
||||||
|
AttachmentValidator.cast_and_validate(attachment)
|
||||||
|
|> Ecto.Changeset.apply_action(:insert)
|
||||||
|
end
|
||||||
|
|
||||||
test "it turns mastodon attachments into our attachments" do
|
test "it turns mastodon attachments into our attachments" do
|
||||||
attachment = %{
|
attachment = %{
|
||||||
"url" =>
|
"url" =>
|
||||||
|
@ -103,6 +117,27 @@ test "validates for a basic object with an attachment", %{
|
||||||
assert object["attachment"]
|
assert object["attachment"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "validates for a basic object with an attachment in an array", %{
|
||||||
|
valid_chat_message: valid_chat_message,
|
||||||
|
user: user
|
||||||
|
} do
|
||||||
|
file = %Plug.Upload{
|
||||||
|
content_type: "image/jpg",
|
||||||
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
filename: "an_image.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
|
valid_chat_message =
|
||||||
|
valid_chat_message
|
||||||
|
|> Map.put("attachment", [attachment.data])
|
||||||
|
|
||||||
|
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
|
||||||
|
|
||||||
|
assert object["attachment"]
|
||||||
|
end
|
||||||
|
|
||||||
test "validates for a basic object with an attachment but without content", %{
|
test "validates for a basic object with an attachment but without content", %{
|
||||||
valid_chat_message: valid_chat_message,
|
valid_chat_message: valid_chat_message,
|
||||||
user: user
|
user: user
|
||||||
|
|
Loading…
Reference in a new issue