2017-09-13 16:00:30 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-09-13 16:00:30 +01:00
|
|
|
namespace App\Services;
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
use App\Models\Note;
|
2023-02-18 09:34:57 +00:00
|
|
|
use Illuminate\Http\Response;
|
2017-09-13 16:00:30 +01:00
|
|
|
|
|
|
|
class ActivityStreamsService
|
|
|
|
{
|
2018-01-15 14:02:13 +00:00
|
|
|
/**
|
|
|
|
* Return the relevant data to an AS2.0 request to the root path.
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function siteOwnerResponse(): Response
|
2017-09-13 16:00:30 +01:00
|
|
|
{
|
|
|
|
$data = json_encode([
|
|
|
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
|
|
|
'id' => config('app.url'),
|
|
|
|
'type' => 'Person',
|
2017-09-13 17:36:20 +01:00
|
|
|
'name' => config('user.displayname'),
|
|
|
|
'preferredUsername' => config('user.username'),
|
2017-09-13 16:00:30 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
return response($data)->header('Content-Type', 'application/activity+json');
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
/**
|
|
|
|
* Return the relevant data to an AS2.0 request for a particular note.
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function singleNoteResponse(Note $note): Response
|
2017-09-13 16:00:30 +01:00
|
|
|
{
|
|
|
|
$data = json_encode([
|
|
|
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
2017-09-13 17:36:48 +01:00
|
|
|
'summary' => strtok(config('user.displayname'), ' ') . ' added a note to their microblog',
|
2017-09-13 16:00:30 +01:00
|
|
|
'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',
|
2017-09-13 17:36:20 +01:00
|
|
|
'href' => config('app.url') . '/assets/img/profile.jpg',
|
2017-09-13 16:00:30 +01:00
|
|
|
'mediaType' => '/image/jpeg',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'object' => [
|
|
|
|
'id' => $note->longurl,
|
|
|
|
'type' => 'Note',
|
|
|
|
'url' => $note->longurl,
|
2017-09-13 17:02:31 +00:00
|
|
|
'name' => strip_tags($note->note),
|
2017-09-13 16:00:30 +01:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
return response($data)->header('Content-Type', 'application/activity+json');
|
|
|
|
}
|
|
|
|
}
|