[ActivityPub] Add ActivityToType
Minor bug fixes
This commit is contained in:
@@ -25,9 +25,9 @@ abstract class AS2ToEntity
|
||||
};
|
||||
}
|
||||
|
||||
public static function activity_stream_two_object_type_to_gs_table($verb)
|
||||
public static function activity_stream_two_object_type_to_gs_table($object)
|
||||
{
|
||||
return match ($verb) {
|
||||
return match ($object) {
|
||||
'Note' => 'note',
|
||||
default => throw new ClientException('Invalid verb'),
|
||||
};
|
||||
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plugin\ActivityPub\Util\Model\EntityToType;
|
||||
|
||||
use App\Core\Router\Router;
|
||||
use App\Entity\Activity;
|
||||
use App\Util\Exception\ClientException;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Plugin\ActivityPub\Util\Type;
|
||||
|
||||
class ActivityToType
|
||||
{
|
||||
public static function gs_verb_to_activity_stream_two_verb($verb)
|
||||
{
|
||||
return match ($verb) {
|
||||
'create' => 'Create',
|
||||
default => throw new ClientException('Invalid verb'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function translate(Activity $activity): Type\Core\Activity
|
||||
{
|
||||
$attr = [
|
||||
'type' => self::gs_verb_to_activity_stream_two_verb($activity->getVerb()),
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => Router::url('activity_view', ['id' => $activity->getId()], Router::ABSOLUTE_URL),
|
||||
'published' => $activity->getCreated()->format(DateTimeInterface::RFC3339),
|
||||
'attributedTo' => $activity->getActor()->getUri(Router::ABSOLUTE_URL),
|
||||
//'to' => $to,
|
||||
//'cc' => $cc,
|
||||
'object' => $activity->getObject()->getUrl(),
|
||||
];
|
||||
return Type::create($attr);
|
||||
}
|
||||
}
|
@@ -11,12 +11,15 @@ use Plugin\ActivityPub\Util\Type;
|
||||
abstract class EntityToType
|
||||
{
|
||||
/**
|
||||
* @return Type
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function translate(Entity $entity): Type
|
||||
public static function translate(Entity $entity): mixed
|
||||
{
|
||||
switch ($entity::class) {
|
||||
case 'Note':
|
||||
case 'App\Entity\Activity':
|
||||
return ActivityToType::translate($entity);
|
||||
case 'App\Entity\Note':
|
||||
return NoteToType::translate($entity);
|
||||
default:
|
||||
$map = [
|
||||
|
@@ -17,12 +17,11 @@ class NoteToType
|
||||
*/
|
||||
public static function translate(Note $note): Type\Extended\Object\Note
|
||||
{
|
||||
$attributedTo = null;
|
||||
$attr = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL),
|
||||
'published' => $note->getCreated()->format(DateTimeInterface::RFC3339),
|
||||
'attributedTo' => $attributedTo,
|
||||
'attributedTo' => $note->getActor()->getUri(Router::ABSOLUTE_URL),
|
||||
//'to' => $to,
|
||||
//'cc' => $cc,
|
||||
'content' => json_encode($note->getRendered()),
|
||||
|
Reference in New Issue
Block a user