Browse Source

also parse the object inside Create activities

pull/78/head v1.6.3
Aaron Parecki 6 years ago
parent
commit
7252d5a3f4
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 163 additions and 0 deletions
  1. +5
    -0
      lib/XRay/Formats/ActivityStreams.php
  2. +18
    -0
      tests/ActivityStreamsTest.php
  3. +75
    -0
      tests/data/activitystreams.example/create.json
  4. +65
    -0
      tests/data/activitystreams.example/jamey

+ 5
- 0
lib/XRay/Formats/ActivityStreams.php View File

@ -29,6 +29,11 @@ class ActivityStreams extends Format {
if(!isset($as2['type']))
return false;
if($as2['type'] == 'Create' && is_array($as2['object'])) {
// Extract the object and parse that instead
$as2 = $as2['object'];
}
switch($as2['type']) {
case 'Person':
return self::parseAsHCard($as2, $url, $http, $opts);

+ 18
- 0
tests/ActivityStreamsTest.php View File

@ -209,5 +209,23 @@ class ActivityStreamsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['data']['content']['text']);
}
public function testNoteWrappedInCreate() {
$url = 'http://activitystreams.example/create.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://toot.cat/@jamey/100471682482196371', $data['data']['url']);
$this->assertEquals('2018-07-31T22:30:09+00:00', $data['data']['published']);
$this->assertEquals('@darius Huh, I just have never encountered anyone using the phrase generically like that.But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using https://fed.brid.gy/ as an alternative to implementing ActivityPub yourself...', $data['data']['content']['text']);
$this->assertEquals('https://social.tinysubversions.com/users/darius/statuses/100471614681787834', $data['data']['in-reply-to'][0]);
$this->assertEquals('Jamey Sharp', $data['data']['author']['name']);
$this->assertEquals('https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://toot.cat/@jamey', $data['data']['author']['url']);
}
}

+ 75
- 0
tests/data/activitystreams.example/create.json View File

@ -0,0 +1,75 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 30 Jul 2018 03:29:14 GMT
Content-Type: application/activity+json
Connection: keep-alive
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"sensitive": "as:sensitive",
"movedTo": "as:movedTo",
"Hashtag": "as:Hashtag",
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"focalPoint": {
"@container": "@list",
"@id": "toot:focalPoint"
},
"featured": "toot:featured"
}
],
"id": "https://toot.cat/users/jamey/statuses/100471682482196371/activity",
"type": "Create",
"actor": "https://toot.cat/users/jamey",
"published": "2018-07-31T22:30:09Z",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://toot.cat/users/jamey/followers",
"https://social.tinysubversions.com/users/darius"
],
"object": {
"id": "https://toot.cat/users/jamey/statuses/100471682482196371",
"type": "Note",
"summary": null,
"content": "<p><span class=\"h-card\"><a href=\"https://social.tinysubversions.com/@darius\" class=\"u-url mention\">@<span>darius</span></a></span> Huh, I just have never encountered anyone using the phrase generically like that.</p><p>But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using <a href=\"https://fed.brid.gy/\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">fed.brid.gy/</span><span class=\"invisible\"></span></a> as an alternative to implementing ActivityPub yourself...</p>",
"inReplyTo": "https://social.tinysubversions.com/users/darius/statuses/100471614681787834",
"published": "2018-07-31T22:30:09Z",
"url": "https://toot.cat/@jamey/100471682482196371",
"attributedTo": "http://activitystreams.example/jamey",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://toot.cat/users/jamey/followers",
"https://social.tinysubversions.com/users/darius"
],
"sensitive": false,
"atomUri": "https://toot.cat/users/jamey/statuses/100471682482196371",
"inReplyToAtomUri": "https://social.tinysubversions.com/users/darius/statuses/100471614681787834",
"conversation": "tag:tinysubversions.com,2018-07-31:objectId=141754:objectType=Conversation",
"attachment": [],
"tag": [
{
"type": "Mention",
"href": "https://social.tinysubversions.com/users/darius",
"name": "@darius@tinysubversions.com"
}
]
},
"signature": {
"type": "RsaSignature2017",
"creator": "https://toot.cat/users/jamey#main-key",
"created": "2018-07-31T22:30:10Z",
"signatureValue": "EV0Bv0kRqOQLiHYHwcy0ElgPNkOPXfQ1ygpAG028b24a3bwCmw3JQO/AyfxTyqf7MgUUVGMR8sFYQA4+MeZPCH39R3xdZ4K8Ce0GEv+GxT34jpIQkB4LQsL7X9GZFo6M20cP9m3197zU+/giPBjnOHfPJr61wHkkHklHfKVK13mmR4pqrrr6TOecXfr32n3y2+3qtrGIWBWl6DaDKK6aQTaXxu66wxbmIhIIcAvS7oQVvDMqXKuDrCfT+3wiVm+6mGENU1WtiiVEtpC9gfcXEbRWPhI35AHP+4ruuIvoZL3pOMk5fuCrnAbL3Vn0uFPrsh7JY19UbPrNRyK3je5oog=="
}
}

+ 65
- 0
tests/data/activitystreams.example/jamey View File

@ -0,0 +1,65 @@
HTTP/1.1 200 OK
Date: Tue, 31 Jul 2018 22:46:57 GMT
Content-Type: application/activity+json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: Mastodon
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Link: <https://toot.cat/.well-known/webfinger?resource=acct%3Ajamey%40toot.cat>; rel="lrdd"; type="application/xrd+xml", <https://toot.cat/users/jamey.atom>; rel="alternate"; type="application/atom+xml", <https://toot.cat/users/jamey>; rel="alternate"; type="application/activity+json"
Vary: Accept,Accept-Encoding
Cache-Control: max-age=180, public
ETag: W/"e354d3ca6ebb3ebfdfbe129a17d2cfbc"
X-Request-Id: c3e7bab2-2cf2-4f2b-a380-7c6feb991704
X-Runtime: 0.178355
Strict-Transport-Security: max-age=31536000; includeSubDomains
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"sensitive": "as:sensitive",
"movedTo": "as:movedTo",
"Hashtag": "as:Hashtag",
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"focalPoint": {
"@container": "@list",
"@id": "toot:focalPoint"
},
"featured": "toot:featured"
}
],
"id": "https://toot.cat/users/jamey",
"type": "Person",
"following": "https://toot.cat/users/jamey/following",
"followers": "https://toot.cat/users/jamey/followers",
"inbox": "https://toot.cat/users/jamey/inbox",
"outbox": "https://toot.cat/users/jamey/outbox",
"featured": "https://toot.cat/users/jamey/collections/featured",
"preferredUsername": "jamey",
"name": "Jamey Sharp",
"summary": "<p>Making the computer boxes do what they&apos;re supposed to, and nothing else : <a href=\"https://jamey.thesharps.us\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">jamey.thesharps.us</span><span class=\"invisible\"></span></a> : <a href=\"https://liberapay.com/jamey/\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">liberapay.com/jamey/</span><span class=\"invisible\"></span></a> : 30s, he/they</p>",
"url": "https://toot.cat/@jamey",
"manuallyApprovesFollowers": false,
"publicKey": {
"id": "https://toot.cat/users/jamey#main-key",
"owner": "https://toot.cat/users/jamey",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm6OHTzDVR+hineYdFpUE\r\ngNJax20CjDWGl0jslR7sfcVSvc8UZ+IjooHeq8rTDA2NhVvnDevvaBpUmVqYg5bT\r\n0b6kQnyhI/RlUtLC4DpbA2pCitzBJ9S20NCVPX2YYZg6Hpbx1AY0vre2Od6N3M1p\r\nct+peO654xz4a0sRMSgqgxzyehBc1ovW4KXL927dytWu6N/b3572qI3SoTTLHTOA\r\nKrWrXMGWbKWEEV/3FqgcSUw49Kss3wh+0nko/dyxY0+SGsckxkJQvQFQRtoGO6OQ\r\nGscuox65dokqIvyBujfmSC46F69tWNOtrRGHMQ433LmWbDZW7dGVShH5bG2itMeD\r\n8wIDAQAB\r\n-----END PUBLIC KEY-----\r\n"
},
"endpoints": {
"sharedInbox": "https://toot.cat/inbox"
},
"icon": {
"type": "Image",
"mediaType": "image/jpeg",
"url": "https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg"
}
}

Loading…
Cancel
Save