Fix attachments in polls
This commit is contained in:
parent
d713930ea7
commit
c19bdc811e
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UrlObjectValidator do
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
field(:href, ObjectValidators.Uri)
|
field(:href, ObjectValidators.Uri)
|
||||||
field(:mediaType, :string)
|
field(:mediaType, :string, default: "application/octet-stream")
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(struct, data) do
|
def changeset(struct, data) do
|
||||||
|
|
|
@ -240,13 +240,17 @@ def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachm
|
||||||
|
|
||||||
if href do
|
if href do
|
||||||
attachment_url =
|
attachment_url =
|
||||||
%{"href" => href}
|
%{
|
||||||
|
"href" => href,
|
||||||
|
"type" => Map.get(url || %{}, "type", "Link")
|
||||||
|
}
|
||||||
|> Maps.put_if_present("mediaType", media_type)
|
|> Maps.put_if_present("mediaType", media_type)
|
||||||
|> Maps.put_if_present("type", Map.get(url || %{}, "type"))
|
|
||||||
|
|
||||||
%{"url" => [attachment_url]}
|
%{
|
||||||
|
"url" => [attachment_url],
|
||||||
|
"type" => data["type"] || "Document"
|
||||||
|
}
|
||||||
|> Maps.put_if_present("mediaType", media_type)
|
|> Maps.put_if_present("mediaType", media_type)
|
||||||
|> Maps.put_if_present("type", data["type"])
|
|
||||||
|> Maps.put_if_present("name", data["name"])
|
|> Maps.put_if_present("name", data["name"])
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
|
99
test/fixtures/tesla_mock/poll_attachment.json
vendored
Normal file
99
test/fixtures/tesla_mock/poll_attachment.json
vendored
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://patch.cx/schemas/litepub-0.1.jsonld",
|
||||||
|
{
|
||||||
|
"@language": "und"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actor": "https://patch.cx/users/rin",
|
||||||
|
"anyOf": [],
|
||||||
|
"attachment": [
|
||||||
|
{
|
||||||
|
"mediaType": "image/jpeg",
|
||||||
|
"name": "screenshot_mpv:Totoro@01:18:44.345.jpg",
|
||||||
|
"type": "Document",
|
||||||
|
"url": "https://shitposter.club/media/3bb4c4d402f8fdcc7f80963c3d7cf6f10f936897fd374922ade33199d2f86d87.jpg?name=screenshot_mpv%3ATotoro%4001%3A18%3A44.345.jpg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributedTo": "https://patch.cx/users/rin",
|
||||||
|
"cc": [
|
||||||
|
"https://patch.cx/users/rin/followers"
|
||||||
|
],
|
||||||
|
"closed": "2020-06-19T23:22:02.754678Z",
|
||||||
|
"content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"9vwjTNzEWEM1TfkBGq\" href=\"https://mastodon.sdf.org/users/rinpatch\" rel=\"ugc\">@<span>rinpatch</span></a></span>",
|
||||||
|
"closed": "2019-09-19T00:32:36.785333",
|
||||||
|
"content": "can you vote on this poll?",
|
||||||
|
"id": "https://patch.cx/objects/tesla_mock/poll_attachment",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"name": "a",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 0,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "A",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 0,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Aa",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 0,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AA",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 0,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AAa",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 1,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AAA",
|
||||||
|
"replies": {
|
||||||
|
"totalItems": 3,
|
||||||
|
"type": "Collection"
|
||||||
|
},
|
||||||
|
"type": "Note"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"published": "2020-06-19T23:12:02.786113Z",
|
||||||
|
"sensitive": false,
|
||||||
|
"summary": "",
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"href": "https://mastodon.sdf.org/users/rinpatch",
|
||||||
|
"name": "@rinpatch@mastodon.sdf.org",
|
||||||
|
"type": "Mention"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"https://mastodon.sdf.org/users/rinpatch"
|
||||||
|
],
|
||||||
|
"type": "Question",
|
||||||
|
"voters": [
|
||||||
|
"https://shitposter.club/users/moonman",
|
||||||
|
"https://skippers-bin.com/users/7v1w1r8ce6",
|
||||||
|
"https://mastodon.sdf.org/users/rinpatch",
|
||||||
|
"https://mastodon.social/users/emelie"
|
||||||
|
]
|
||||||
|
}
|
|
@ -177,6 +177,13 @@ test "handle HTTP 404 response" do
|
||||||
"https://mastodon.example.org/users/userisgone404"
|
"https://mastodon.example.org/users/userisgone404"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it can fetch pleroma polls with attachments" do
|
||||||
|
{:ok, object} =
|
||||||
|
Fetcher.fetch_object_from_id("https://patch.cx/objects/tesla_mock/poll_attachment")
|
||||||
|
|
||||||
|
assert object
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "pruning" do
|
describe "pruning" do
|
||||||
|
|
|
@ -82,6 +82,14 @@ def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/tesla_mock/poll_attachment.json")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
def get(
|
def get(
|
||||||
"https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
|
"https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
|
||||||
_,
|
_,
|
||||||
|
|
|
@ -620,7 +620,8 @@ test "it remaps video URLs as attachments if necessary" do
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||||
"mediaType" => "video/mp4"
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -639,7 +640,8 @@ test "it remaps video URLs as attachments if necessary" do
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||||
"mediaType" => "video/mp4"
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1459,8 +1461,13 @@ test "returns modified object when attachment is map" do
|
||||||
"attachment" => [
|
"attachment" => [
|
||||||
%{
|
%{
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Document",
|
||||||
"url" => [
|
"url" => [
|
||||||
%{"href" => "https://peertube.moe/stat-480.mp4", "mediaType" => "video/mp4"}
|
%{
|
||||||
|
"href" => "https://peertube.moe/stat-480.mp4",
|
||||||
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1477,14 +1484,24 @@ test "returns modified object when attachment is list" do
|
||||||
"attachment" => [
|
"attachment" => [
|
||||||
%{
|
%{
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Document",
|
||||||
"url" => [
|
"url" => [
|
||||||
%{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
|
%{
|
||||||
|
"href" => "https://pe.er/stat-480.mp4",
|
||||||
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Document",
|
||||||
"url" => [
|
"url" => [
|
||||||
%{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
|
%{
|
||||||
|
"href" => "https://pe.er/stat-480.mp4",
|
||||||
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue