Merge branch 'bugfix/as2-contentmap' into 'develop'
handle ActivityStreams 2.0 contentMap See merge request pleroma/pleroma!229
This commit is contained in:
commit
de80363518
@ -24,6 +24,7 @@ def fix_object(object) do
|
|||||||
|> fix_in_reply_to
|
|> fix_in_reply_to
|
||||||
|> fix_emoji
|
|> fix_emoji
|
||||||
|> fix_tag
|
|> fix_tag
|
||||||
|
|> fix_content_map
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
|
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
|
||||||
@ -107,6 +108,17 @@ def fix_tag(object) do
|
|||||||
|> Map.put("tag", combined)
|
|> Map.put("tag", combined)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# content map usually only has one language so this will do for now.
|
||||||
|
def fix_content_map(%{"contentMap" => content_map} = object) do
|
||||||
|
content_groups = Map.to_list(content_map)
|
||||||
|
{_, content} = Enum.at(content_groups, 0)
|
||||||
|
|
||||||
|
object
|
||||||
|
|> Map.put("content", content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_content_map(object), do: object
|
||||||
|
|
||||||
# TODO: validate those with a Ecto scheme
|
# TODO: validate those with a Ecto scheme
|
||||||
# - tags
|
# - tags
|
||||||
# - emoji
|
# - emoji
|
||||||
|
67
test/fixtures/mastodon-post-activity-contentmap.json
vendored
Normal file
67
test/fixtures/mastodon-post-activity-contentmap.json
vendored
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"Emoji": "toot:Emoji",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"toot": "http://joinmastodon.org/ns#"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actor": "http://mastodon.example.org/users/admin",
|
||||||
|
"cc": [
|
||||||
|
"http://mastodon.example.org/users/admin/followers",
|
||||||
|
"http://localtesting.pleroma.lol/users/lain"
|
||||||
|
],
|
||||||
|
"id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity",
|
||||||
|
"nickname": "lain",
|
||||||
|
"object": {
|
||||||
|
"atomUri": "http://mastodon.example.org/users/admin/statuses/99512778738411822",
|
||||||
|
"attachment": [],
|
||||||
|
"attributedTo": "http://mastodon.example.org/users/admin",
|
||||||
|
"cc": [
|
||||||
|
"http://mastodon.example.org/users/admin/followers",
|
||||||
|
"http://localtesting.pleroma.lol/users/lain"
|
||||||
|
],
|
||||||
|
"contentMap": {
|
||||||
|
"en": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
||||||
|
},
|
||||||
|
"conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
|
||||||
|
"id": "http://mastodon.example.org/users/admin/statuses/99512778738411822",
|
||||||
|
"inReplyTo": null,
|
||||||
|
"inReplyToAtomUri": null,
|
||||||
|
"published": "2018-02-12T14:08:20Z",
|
||||||
|
"sensitive": true,
|
||||||
|
"summary": "cw",
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"href": "http://localtesting.pleroma.lol/users/lain",
|
||||||
|
"name": "@lain@localtesting.pleroma.lol",
|
||||||
|
"type": "Mention"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"type": "Note",
|
||||||
|
"url": "http://mastodon.example.org/@admin/99512778738411822"
|
||||||
|
},
|
||||||
|
"published": "2018-02-12T14:08:20Z",
|
||||||
|
"signature": {
|
||||||
|
"created": "2018-02-12T14:08:20Z",
|
||||||
|
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||||
|
"signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==",
|
||||||
|
"type": "RsaSignature2017"
|
||||||
|
},
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"type": "Create"
|
||||||
|
}
|
@ -102,6 +102,16 @@ test "it works for incoming notices with hashtags" do
|
|||||||
assert Enum.at(data["object"]["tag"], 2) == "moo"
|
assert Enum.at(data["object"]["tag"], 2) == "moo"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works for incoming notices with contentMap" do
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert data["object"]["content"] ==
|
||||||
|
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
||||||
|
end
|
||||||
|
|
||||||
test "it works for incoming follow requests" do
|
test "it works for incoming follow requests" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user