2021-08-24 20:29:26 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-04 17:00:58 +01:00
|
|
|
namespace Plugin\ActivityPub\Util\Model\EntityToType;
|
2021-08-24 20:29:26 +01:00
|
|
|
|
2021-10-04 17:00:58 +01:00
|
|
|
use App\Core\Event;
|
2021-08-24 20:29:26 +01:00
|
|
|
use App\Core\Router\Router;
|
|
|
|
use App\Entity\Note;
|
|
|
|
use DateTimeInterface;
|
2021-10-04 17:00:58 +01:00
|
|
|
use Plugin\ActivityPub\Util\Type;
|
2021-08-24 20:29:26 +01:00
|
|
|
|
|
|
|
class NoteToType
|
|
|
|
{
|
|
|
|
/**
|
2021-09-06 23:47:28 +01:00
|
|
|
* @param Note $note
|
2021-08-24 20:29:26 +01:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*
|
|
|
|
* @return Type
|
|
|
|
*/
|
|
|
|
public static function translate(Note $note)
|
|
|
|
{
|
2021-10-04 17:00:58 +01:00
|
|
|
$attributedTo = null;
|
|
|
|
Event::handle('FreeNetworkGenerateLocalActorUri', ['source' => 'ActivityPub', 'actor_id' => $note->getActorId(), 'actor_uri' => &$attributedTo]);
|
2021-08-24 20:29:26 +01:00
|
|
|
$attr = [
|
2021-09-20 17:04:24 +01:00
|
|
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
|
|
|
'id' => Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL),
|
|
|
|
'published' => $note->getCreated()->format(DateTimeInterface::RFC3339),
|
2021-10-04 17:00:58 +01:00
|
|
|
'attributedTo' => $attributedTo,
|
2021-08-24 20:29:26 +01:00
|
|
|
//'to' => $to,
|
|
|
|
//'cc' => $cc,
|
2021-09-20 17:04:24 +01:00
|
|
|
'content' => json_encode($note->getRendered()),
|
2021-08-24 20:29:26 +01:00
|
|
|
//'tag' => $tags
|
|
|
|
];
|
|
|
|
return Type::create(type: 'Note', attributes: $attr);
|
|
|
|
}
|
2021-09-06 23:47:28 +01:00
|
|
|
}
|