Handle incoming Question objects

This commit is contained in:
rinpatch 2019-05-15 20:10:16 +03:00
parent 131f883207
commit 62e42b03ab
6 changed files with 190 additions and 2 deletions

View File

@ -399,7 +399,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# - tags # - tags
# - emoji # - emoji
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data) def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
when objtype in ["Article", "Note", "Video", "Page"] do when objtype in ["Article", "Note", "Video", "Page", "Question"] do
actor = Containment.get_actor(data) actor = Containment.get_actor(data)
data = data =

View File

@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
require Logger require Logger
@supported_object_types ["Article", "Note", "Video", "Page"] @supported_object_types ["Article", "Note", "Video", "Page", "Question"]
# Some implementations send the actor URI as the actor field, others send the entire actor object, # Some implementations send the actor URI as the actor field, others send the entire actor object,
# so figure out what the actor's URI is based on what we have. # so figure out what the actor's URI is based on what we have.

View File

@ -0,0 +1,64 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"toot": "http://joinmastodon.org/ns#",
"featured": {
"@id": "toot:featured",
"@type": "@id"
},
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"
},
"movedTo": {
"@id": "as:movedTo",
"@type": "@id"
},
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"Hashtag": "as:Hashtag",
"Emoji": "toot:Emoji",
"IdentityProof": "toot:IdentityProof",
"focalPoint": {
"@container": "@list",
"@id": "toot:focalPoint"
}
}
],
"id": "https://mastodon.sdf.org/users/rinpatch",
"type": "Person",
"following": "https://mastodon.sdf.org/users/rinpatch/following",
"followers": "https://mastodon.sdf.org/users/rinpatch/followers",
"inbox": "https://mastodon.sdf.org/users/rinpatch/inbox",
"outbox": "https://mastodon.sdf.org/users/rinpatch/outbox",
"featured": "https://mastodon.sdf.org/users/rinpatch/collections/featured",
"preferredUsername": "rinpatch",
"name": "rinpatch",
"summary": "<p>umu</p>",
"url": "https://mastodon.sdf.org/@rinpatch",
"manuallyApprovesFollowers": false,
"publicKey": {
"id": "https://mastodon.sdf.org/users/rinpatch#main-key",
"owner": "https://mastodon.sdf.org/users/rinpatch",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1vbhYKDopb5xzfJB2TZY\n0ZvgxqdAhbSKKkQC5Q2b0ofhvueDy2AuZTnVk1/BbHNlqKlwhJUSpA6LiTZVvtcc\nMn6cmSaJJEg30gRF5GARP8FMcuq8e2jmceiW99NnUX17MQXsddSf2JFUwD0rUE8H\nBsgD7UzE9+zlA/PJOTBO7fvBEz9PTQ3r4sRMTJVFvKz2MU/U+aRNTuexRKMMPnUw\nfp6VWh1F44VWJEQOs4tOEjGiQiMQh5OfBk1w2haT3vrDbQvq23tNpUP1cRomLUtx\nEBcGKi5DMMBzE1RTVT1YUykR/zLWlA+JSmw7P6cWtsHYZovs8dgn8Po3X//6N+ng\nTQIDAQAB\n-----END PUBLIC KEY-----\n"
},
"tag": [],
"attachment": [],
"endpoints": {
"sharedInbox": "https://mastodon.sdf.org/inbox"
},
"icon": {
"type": "Image",
"mediaType": "image/jpeg",
"url": "https://mastodon.sdf.org/system/accounts/avatars/000/067/580/original/bf05521bf711b7a0.jpg?1533238802"
},
"image": {
"type": "Image",
"mediaType": "image/gif",
"url": "https://mastodon.sdf.org/system/accounts/headers/000/067/580/original/a99b987e798f7063.gif?1533278217"
}
}

View File

@ -0,0 +1,99 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"sensitive": "as:sensitive",
"Hashtag": "as:Hashtag",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"focalPoint": {
"@container": "@list",
"@id": "toot:focalPoint"
}
}
],
"id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/activity",
"type": "Create",
"actor": "https://mastodon.sdf.org/users/rinpatch",
"published": "2019-05-10T09:03:36Z",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://mastodon.sdf.org/users/rinpatch/followers"
],
"object": {
"id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304",
"type": "Question",
"summary": null,
"inReplyTo": null,
"published": "2019-05-10T09:03:36Z",
"url": "https://mastodon.sdf.org/@rinpatch/102070944809637304",
"attributedTo": "https://mastodon.sdf.org/users/rinpatch",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://mastodon.sdf.org/users/rinpatch/followers"
],
"sensitive": false,
"atomUri": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304",
"inReplyToAtomUri": null,
"conversation": "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation",
"content": "<p>Why is Tenshi eating a corndog so cute?</p>",
"contentMap": {
"en": "<p>Why is Tenshi eating a corndog so cute?</p>"
},
"endTime": "2019-05-11T09:03:36Z",
"closed": "2019-05-11T09:03:36Z",
"attachment": [],
"tag": [],
"replies": {
"id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/replies",
"type": "Collection",
"first": {
"type": "CollectionPage",
"partOf": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/replies",
"items": []
}
},
"oneOf": [
{
"type": "Note",
"name": "Dunno",
"replies": {
"type": "Collection",
"totalItems": 0
}
},
{
"type": "Note",
"name": "Everyone knows that!",
"replies": {
"type": "Collection",
"totalItems": 1
}
},
{
"type": "Note",
"name": "25 char limit is dumb",
"replies": {
"type": "Collection",
"totalItems": 0
}
},
{
"type": "Note",
"name": "I can't even fit a funny",
"replies": {
"type": "Collection",
"totalItems": 1
}
}
]
}
}

View File

@ -52,6 +52,14 @@ defmodule HttpRequestMock do
}} }}
end end
def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/httpoison_mock/rinpatch.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",
_, _,

View File

@ -113,6 +113,23 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Enum.at(object.data["tag"], 2) == "moo" assert Enum.at(object.data["tag"], 2) == "moo"
end end
test "it works for incoming questions" do
data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
object = Object.normalize(activity)
assert Enum.all?(object.data["oneOf"], fn choice ->
choice["name"] in [
"Dunno",
"Everyone knows that!",
"25 char limit is dumb",
"I can't even fit a funny"
]
end)
end
test "it works for incoming notices with contentMap" do test "it works for incoming notices with contentMap" do
data = data =
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!() File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()