2021-09-14 17:15:37 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-10-04 17:00:58 +01:00
|
|
|
namespace Plugin\ActivityPub\Util\Model\EntityToType;
|
2021-09-14 17:15:37 +01:00
|
|
|
|
2021-10-04 17:00:58 +01:00
|
|
|
use App\Core\Event;
|
2021-09-14 17:15:37 +01:00
|
|
|
use App\Core\Router\Router;
|
2021-09-18 03:22:27 +01:00
|
|
|
use App\Entity\Actor;
|
2021-09-20 17:04:24 +01:00
|
|
|
use Component\Avatar\Avatar;
|
|
|
|
use Component\Avatar\Exception\NoAvatarException;
|
2021-09-14 17:15:37 +01:00
|
|
|
use DateTimeInterface;
|
|
|
|
use Exception;
|
2021-10-19 13:48:50 +01:00
|
|
|
use Plugin\ActivityPub\Entity\ActivitypubRsa;
|
2021-10-04 17:00:58 +01:00
|
|
|
use Plugin\ActivityPub\Util\Type;
|
2021-10-19 13:48:50 +01:00
|
|
|
use Plugin\ActivityPub\Util\Type\Extended\Actor\Person;
|
2021-09-14 17:15:37 +01:00
|
|
|
|
|
|
|
class GSActorToType
|
|
|
|
{
|
|
|
|
/**
|
2021-09-18 03:22:27 +01:00
|
|
|
*@throws Exception
|
2021-09-14 17:15:37 +01:00
|
|
|
*/
|
2021-10-19 13:48:50 +01:00
|
|
|
public static function translate(Actor $gsactor): Person
|
2021-09-14 17:15:37 +01:00
|
|
|
{
|
2021-10-19 13:48:50 +01:00
|
|
|
$rsa = ActivitypubRsa::getByActor($gsactor);
|
|
|
|
$public_key = $rsa->getPublicKey();
|
2021-10-04 17:00:58 +01:00
|
|
|
$uri = null;
|
2021-09-14 17:15:37 +01:00
|
|
|
$attr = [
|
2021-09-20 17:04:24 +01:00
|
|
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
2021-10-19 13:48:50 +01:00
|
|
|
'id' => $gsactor->getUri(Router::ABSOLUTE_URL),
|
2021-09-20 17:04:24 +01:00
|
|
|
'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $gsactor->getId()], Router::ABSOLUTE_URL),
|
|
|
|
'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $gsactor->getId()], Router::ABSOLUTE_URL),
|
|
|
|
'following' => Router::url('actor_subscriptions_id', ['id' => $gsactor->getId()], Router::ABSOLUTE_URL),
|
|
|
|
'followers' => Router::url('actor_subscribers_id', ['id' => $gsactor->getId()], Router::ABSOLUTE_URL),
|
2021-10-26 17:29:14 +01:00
|
|
|
'liked' => Router::url('favourites_view_by_actor_id', ['id' => $gsactor->getId()], Router::ABSOLUTE_URL),
|
2021-09-14 17:15:37 +01:00
|
|
|
//'streams' =>
|
|
|
|
'preferredUsername' => $gsactor->getNickname(),
|
2021-10-19 13:48:50 +01:00
|
|
|
'publicKey' => [
|
|
|
|
'id' => $uri . "#public-key",
|
|
|
|
'owner' => $uri,
|
|
|
|
'publicKeyPem' => $public_key
|
|
|
|
],
|
2021-09-20 17:04:24 +01:00
|
|
|
'name' => $gsactor->getFullname(),
|
|
|
|
'location' => $gsactor->getLocation(),
|
2021-09-14 17:15:37 +01:00
|
|
|
'published' => $gsactor->getCreated()->format(DateTimeInterface::RFC3339),
|
|
|
|
'summary' => $gsactor->getBio(),
|
2021-09-20 17:04:24 +01:00
|
|
|
//'tag' => $gsactor->getSelfTags(),
|
2021-09-14 17:15:37 +01:00
|
|
|
'updated' => $gsactor->getModified()->format(DateTimeInterface::RFC3339),
|
2021-10-19 13:48:50 +01:00
|
|
|
'url' => $gsactor->getUrl(Router::ABSOLUTE_URL),
|
2021-09-14 17:15:37 +01:00
|
|
|
];
|
2021-09-20 17:04:24 +01:00
|
|
|
try {
|
|
|
|
$attr['icon'] = Avatar::getAvatar($gsactor->getId())->getUrl(type: Router::ABSOLUTE_URL);
|
|
|
|
} catch (NoAvatarException) {
|
|
|
|
// No icon for this actor
|
|
|
|
}
|
|
|
|
|
2021-09-14 17:15:37 +01:00
|
|
|
return Type::create(type: 'Person', attributes: $attr);
|
|
|
|
}
|
|
|
|
}
|