diff --git a/src/Factory/ActivityPub/FlagFactory.php b/src/Factory/ActivityPub/FlagFactory.php index 94f94e855..be0ed2485 100644 --- a/src/Factory/ActivityPub/FlagFactory.php +++ b/src/Factory/ActivityPub/FlagFactory.php @@ -6,19 +6,26 @@ use App\Entity\Activity; use App\Entity\Report; +use Doctrine\ORM\EntityManagerInterface; class FlagFactory { - public function __construct() - { + public function __construct( + private readonly EntityManagerInterface $entityManager, + ) { } public function build(Report $report): Activity { $activity = new Activity('Flag'); $activity->setObject($report->getSubject()); + $activity->objectUser = $report->reported; $activity->setActor($report->reporting); $activity->contentString = $report->reason; + $activity->audience = $report->magazine; + + $this->entityManager->persist($activity); + $this->entityManager->flush(); return $activity; } diff --git a/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php b/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php index 95f2b6e85..821053abe 100644 --- a/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php +++ b/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php @@ -48,6 +48,11 @@ public function doWork(MessageInterface $message): void } $this->logger->debug('got a FlagMessage'); $report = $this->reportRepository->find($message->reportId); + if (!$report) { + $this->logger->info("couldn't find report with id {id}", ['id' => $message->reportId]); + + return; + } $this->logger->debug('found the report: '.json_encode($report)); $inboxes = $this->getInboxUrls($report); if (0 === \sizeof($inboxes)) { diff --git a/src/Service/ActivityPub/ActivityJsonBuilder.php b/src/Service/ActivityPub/ActivityJsonBuilder.php index 05c1294b3..805f44b3f 100644 --- a/src/Service/ActivityPub/ActivityJsonBuilder.php +++ b/src/Service/ActivityPub/ActivityJsonBuilder.php @@ -240,7 +240,7 @@ public function buildFlagFromActivity(Activity $activity): array $result = [ '@context' => ActivityPubActivityInterface::CONTEXT_URL, - 'id' => $this->urlGenerator->generate('ap_object', ['report_id' => $activity->uuid], UrlGeneratorInterface::ABSOLUTE_URL), + 'id' => $this->urlGenerator->generate('ap_object', ['id' => $activity->uuid], UrlGeneratorInterface::ABSOLUTE_URL), 'type' => 'Flag', 'actor' => $this->personFactory->getActivityPubId($activity->userActor), 'object' => $object, @@ -258,12 +258,19 @@ public function buildFlagFromActivity(Activity $activity): array public function buildFollowFromActivity(Activity $activity): array { + $object = $activity->getObject(); + if ($object instanceof User) { + $activityObject = $this->personFactory->getActivityPubId($object); + } else { + $activityObject = $this->groupFactory->getActivityPubId($object); + } + return [ '@context' => $this->contextsProvider->referencedContexts(), 'id' => $this->urlGenerator->generate('ap_object', ['id' => $activity->uuid], UrlGeneratorInterface::ABSOLUTE_URL), 'type' => 'Follow', 'actor' => $this->personFactory->getActivityPubId($activity->userActor), - 'object' => $this->personFactory->getActivityPubId($activity->objectUser), + 'object' => $activityObject, ]; } diff --git a/src/Service/ActivityPub/Wrapper/FollowWrapper.php b/src/Service/ActivityPub/Wrapper/FollowWrapper.php index 850b001d3..7e4ad0ce4 100644 --- a/src/Service/ActivityPub/Wrapper/FollowWrapper.php +++ b/src/Service/ActivityPub/Wrapper/FollowWrapper.php @@ -5,6 +5,7 @@ namespace App\Service\ActivityPub\Wrapper; use App\Entity\Activity; +use App\Entity\Magazine; use App\Entity\User; use Doctrine\ORM\EntityManagerInterface; @@ -15,7 +16,7 @@ public function __construct( ) { } - public function build(User $follower, User $following): Activity + public function build(User $follower, User|Magazine $following): Activity { $activity = new Activity('Follow'); $activity->setActor($follower);