From c9d3aafd332eefa1b3550d83c7bf7d60253613cb Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Tue, 17 Dec 2024 23:45:03 +0100 Subject: [PATCH] Use activityPubManager variable consistently --- .../ActivityPub/Inbox/ActivityHandler.php | 12 ++++++------ .../ActivityPub/Outbox/DeliverHandler.php | 4 ++-- .../ActivityPub/UpdateActorHandler.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php index 8e7ab4a4c..14bbaf93b 100644 --- a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php +++ b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php @@ -42,7 +42,7 @@ public function __construct( private readonly SignatureValidator $signatureValidator, private readonly SettingsManager $settingsManager, private readonly MessageBusInterface $bus, - private readonly ActivityPubManager $manager, + private readonly ActivityPubManager $activityPubManager, private readonly ApHttpClient $apHttpClient, private readonly InstanceRepository $instanceRepository, private readonly RemoteInstanceManager $remoteInstanceManager, @@ -119,15 +119,15 @@ public function doWork(MessageInterface $message): void try { if (isset($payload['actor']) || isset($payload['attributedTo'])) { - if (!$this->verifyInstanceDomain($payload['actor'] ?? $this->manager->getSingleActorFromAttributedTo($payload['attributedTo']))) { + if (!$this->verifyInstanceDomain($payload['actor'] ?? $this->activityPubManager->getSingleActorFromAttributedTo($payload['attributedTo']))) { return; } - $user = $this->manager->findActorOrCreate($payload['actor'] ?? $this->manager->getSingleActorFromAttributedTo($payload['attributedTo'])); + $user = $this->activityPubManager->findActorOrCreate($payload['actor'] ?? $this->activityPubManager->getSingleActorFromAttributedTo($payload['attributedTo'])); } else { if (!$this->verifyInstanceDomain($payload['id'])) { return; } - $user = $this->manager->findActorOrCreate($payload['id']); + $user = $this->activityPubManager->findActorOrCreate($payload['id']); } } catch (\Exception $e) { $this->logger->error('[ActivityHandler::doWork] Payload: '.json_encode($payload)); @@ -157,7 +157,7 @@ private function handle(?array $payload) if ('Announce' === $payload['type']) { // we check for an array here, because boosts are announces with an url (string) as the object if (\is_array($payload['object'])) { - $actorObject = $this->manager->findActorOrCreate($payload['actor']); + $actorObject = $this->activityPubManager->findActorOrCreate($payload['actor']); if ($actorObject instanceof Magazine && $actorObject->lastOriginUpdate < (new \DateTime())->modify('-3 hours')) { if (isset($payload['object']['type']) && 'Create' === $payload['object']['type']) { $actorObject->lastOriginUpdate = new \DateTime(); @@ -169,7 +169,7 @@ private function handle(?array $payload) $payload = $payload['object']; $actor = $payload['actor'] ?? $payload['attributedTo'] ?? null; if ($actor) { - $user = $this->manager->findActorOrCreate($actor); + $user = $this->activityPubManager->findActorOrCreate($actor); if ($user instanceof User && null === $user->apId) { // don't do anything if we get an announce activity for something a local user did (unless it's a boost, see comment above) $this->logger->warning('[ActivityHandler::handle] Ignoring this message because it announces an activity from a local user'); diff --git a/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php b/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php index 360cf635d..ee6ef5c4c 100644 --- a/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php +++ b/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php @@ -31,7 +31,7 @@ class DeliverHandler extends MbinMessageHandler public function __construct( private readonly EntityManagerInterface $entityManager, private readonly ApHttpClient $client, - private readonly ActivityPubManager $manager, + private readonly ActivityPubManager $activityPubManager, private readonly SettingsManager $settingsManager, private readonly LoggerInterface $logger, private readonly InstanceRepository $instanceRepository, @@ -120,7 +120,7 @@ public function doWork(MessageInterface $message): void $url = $message->payload['actor']; } $this->logger->debug("Getting Actor for url: $url"); - $actor = $this->manager->findActorOrCreate($url); + $actor = $this->activityPubManager->findActorOrCreate($url); if (!$actor) { $this->logger->debug('got no actor :('); diff --git a/src/MessageHandler/ActivityPub/UpdateActorHandler.php b/src/MessageHandler/ActivityPub/UpdateActorHandler.php index 7f9aa73de..c6bd668b7 100644 --- a/src/MessageHandler/ActivityPub/UpdateActorHandler.php +++ b/src/MessageHandler/ActivityPub/UpdateActorHandler.php @@ -21,7 +21,7 @@ class UpdateActorHandler extends MbinMessageHandler { public function __construct( private readonly EntityManagerInterface $entityManager, - private readonly ActivityPubManager $manager, + private readonly ActivityPubManager $activityPubManager, private readonly ApHttpClient $apHttpClient, private readonly LockFactory $lockFactory, private readonly UserRepository $userRepository, @@ -61,7 +61,7 @@ public function doWork(MessageInterface $message): void $this->apHttpClient->invalidateActorObjectCache($actorUrl); } if ($message->force || $actor->apFetchedAt < (new \DateTime())->modify('-1 hour')) { - $this->manager->updateActor($actorUrl); + $this->activityPubManager->updateActor($actorUrl); } else { $this->logger->debug('not updating actor {url}: last updated is recent: {fetched}', [ 'url' => $actorUrl,