Add AS2.0 data for a note

This commit is contained in:
Jonny Barnes 2017-09-13 15:49:37 +01:00
parent d33793df14
commit f3cfa9324c
2 changed files with 52 additions and 0 deletions

View file

@ -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'));
}

View file

@ -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)
]
]);
}
}