gnu-social/plugins/ActivityPub/Util/Model/EntityToType/GSActorToType.php

60 lines
2.3 KiB
PHP
Raw Normal View History

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