diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index e7c0a965..6e7b379c 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -48,6 +48,34 @@ class NotesController extends Controller { $note = Note::nb60($urlId)->with('webmentions')->firstOrFail(); + if (request()->wantsActivityStream()) { + $data = json_encode([ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'summary' => 'Jonny added a note to his microblog', + 'type' => 'Add', + 'published' => $note->updated_at->toW3cString(), + 'actor' => [ + 'type' => 'Person', + 'id' => config('app.url'), + 'name' => config('app.display_name'), + 'url' => config('app.url'), + 'image' => [ + 'type' => 'Link', + 'href' => config('app.url') . '/assets/img/jmb-bw.jpg', + 'mediaType' => '/image/jpeg', + ], + ], + 'object' => [ + 'id' => $note->longurl, + 'type' => 'Note', + 'url' => $note->longurl, + 'name' => strip_tags($note->note) + ], + ]); + + return response($data)->header('Content-Type', 'application/activity+json'); + } + return view('notes.show', compact('note')); } diff --git a/tests/Feature/ActivityStreamTest.php b/tests/Feature/ActivityStreamTest.php index c990cedf..5d7b2c24 100644 --- a/tests/Feature/ActivityStreamTest.php +++ b/tests/Feature/ActivityStreamTest.php @@ -23,4 +23,28 @@ class ActivityStreamTest extends TestCase 'name' => config('app.display_name'), ]); } + + /** + * Test request to a single note returns AS2.0 data. + * + * @return void + */ + public function test_single_note_returns_as_data() + { + $note = \App\Note::find(11); + $response = $this->get('/notes/B', ['Accept' => 'application/activity+json']); + $response->assertHeader('Content-Type', 'application/activity+json'); + $response->assertJson([ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'type' => 'Add', + 'actor' => [ + 'type' => 'Person', + 'id' => config('app.url'), + ], + 'object' => [ + 'type' => 'Note', + 'name' => strip_tags($note->note) + ] + ]); + } }