From 35241944cfe9c698ddf65d6bd645385c3e989cd3 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 30 Mar 2019 11:31:11 -0400 Subject: [PATCH] Generate IDs for outbox activities before persisting --- src/ActivityEventHandlers/ActivityPersister.php | 13 ++++++++++++- src/Config/ActivityPubModule.php | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ActivityEventHandlers/ActivityPersister.php b/src/ActivityEventHandlers/ActivityPersister.php index 8e67238..f17b52a 100644 --- a/src/ActivityEventHandlers/ActivityPersister.php +++ b/src/ActivityEventHandlers/ActivityPersister.php @@ -3,6 +3,7 @@ namespace ActivityPub\ActivityEventHandlers; use ActivityPub\Objects\CollectionsService; +use ActivityPub\Objects\IdProvider; use ActivityPub\Objects\ObjectsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -18,6 +19,11 @@ class ActivityPersister implements EventSubscriberInterface */ private $objectsService; + /** + * @var IdProvider + */ + private $idProvider; + public static function getSubscribedEvents() { return array( @@ -27,10 +33,12 @@ class ActivityPersister implements EventSubscriberInterface } public function __construct( CollectionsService $collectionsService, - ObjectsService $objectsService ) + ObjectsService $objectsService, + IdProvider $idProvider ) { $this->collectionsService = $collectionsService; $this->objectsService = $objectsService; + $this->idProvider = $idProvider; } public function persistActivityToInbox( InboxActivityEvent $event ) @@ -47,6 +55,9 @@ class ActivityPersister implements EventSubscriberInterface public function persistActivityToOutbox( OutboxActivityEvent $event ) { $activity = $event->getActivity(); + if ( ! array_key_exists( 'id', $activity ) ) { + $activity['id'] = $this->idProvider->getId( $event->getRequest(), "activities" ); + } $receivingActor = $event->getReceivingActor(); if ( $receivingActor->hasField( 'outbox' ) ) { $this->collectionsService->addItem( $receivingActor['outbox'], $activity ); diff --git a/src/Config/ActivityPubModule.php b/src/Config/ActivityPubModule.php index 160c0ad..c8f0f86 100644 --- a/src/Config/ActivityPubModule.php +++ b/src/Config/ActivityPubModule.php @@ -180,7 +180,8 @@ class ActivityPubModule $this->injector->register( ActivityPersister::class, ActivityPersister::class ) ->addArgument( new Reference( CollectionsService::class ) ) - ->addArgument( new Reference( ObjectsService::class ) ); + ->addArgument( new Reference( ObjectsService::class ) ) + ->addArgument( new Reference( IdProvider::class ) ); } /**