Skip to content

Commit

Permalink
Don't federate anything from the random magazine (#1236)
Browse files Browse the repository at this point in the history
Co-authored-by: Melroy van den Berg <[email protected]>
  • Loading branch information
BentiGorlich and melroy89 authored Nov 24, 2024
1 parent acf1f81 commit af60baa
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function buildResponse(WebfingerResponseEvent $event): void

protected function getActor($name): ?Magazine
{
if ('random' === $name) {
return null;
}

return $this->magazineRepository->findOneByName($name);
}
}
4 changes: 4 additions & 0 deletions src/EventSubscriber/ActivityPub/GroupWebFingerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function buildResponse(WebfingerResponseEvent $event): void

protected function getActor($name): ?Magazine
{
if ('random' === $name) {
return null;
}

return $this->magazineRepository->findOneByName($name);
}
}
4 changes: 4 additions & 0 deletions src/MessageHandler/ActivityPub/Outbox/AddHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function doWork(MessageInterface $message): void
if ($magazine->apId) {
$audience = [$magazine->apInboxUrl];
} else {
if ('random' === $magazine->name) {
// do not federate the random magazine
return;
}
$audience = $this->magazineRepository->findAudience($magazine);
}

Expand Down
4 changes: 4 additions & 0 deletions src/MessageHandler/ActivityPub/Outbox/AnnounceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function doWork(MessageInterface $message): void
$this->activityPubManager->createInboxesFromCC($activity, $actor),
);
} elseif ($actor instanceof Magazine) {
if ('random' === $actor->name) {
// do not federate the random magazine
return;
}
$createHost = parse_url($object->apId, PHP_URL_HOST);
$inboxes = array_filter(array_merge(
$inboxes,
Expand Down
5 changes: 4 additions & 1 deletion src/MessageHandler/ActivityPub/Outbox/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ public function doWork(MessageInterface $message): void
$receivers = [
...$this->userRepository->findAudience($entity->user),
...$this->activityPubManager->createInboxesFromCC($activity, $entity->user),
...$this->magazineRepository->findAudience($entity->magazine),
];
if ('random' !== $entity->magazine->name) {
// only add the magazine subscribers if it is not the random magazine
$receivers = array_merge($receivers, $this->magazineRepository->findAudience($entity->magazine));
}
$this->logger->debug('sending create activity to {p}', ['p' => $receivers]);
}
$this->deliverManager->deliver(array_filter(array_unique($receivers)), $activity);
Expand Down
10 changes: 9 additions & 1 deletion src/MessageHandler/ActivityPub/Outbox/DeleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ public function doWork(MessageInterface $message): void
$inboxes = array_filter(array_unique(array_merge(
$this->userRepository->findAudience($user),
$this->activityPubManager->createInboxesFromCC($message->payload, $user),
$this->magazineRepository->findAudience($magazine)
)));

if ('random' !== $magazine->name) {
// only add the magazine subscribers if it is not the random magazine
$inboxes = array_filter(array_unique(array_merge(
$inboxes,
$this->magazineRepository->findAudience($magazine),
)));
}

$this->deliverManager->deliver($inboxes, $message->payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function doWork(MessageInterface $message): void
return;
}

if ('random' === $entry->magazine->name) {
// do not federate the random magazine
return;
}

if ($message->sticky) {
$activity = $this->addRemoveFactory->buildAddPinnedPost($user, $entry);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function doWork(MessageInterface $message): void
if (null !== $magazine->apId) {
return;
}

if ('random' === $magazine->name) {
// do not federate the random magazine
return;
}
$magazineUrl = $this->urlGenerator->generate('ap_magazine', ['name' => $magazine->name], UrlGeneratorInterface::ABSOLUTE_URL);
$announce = $this->announceWrapper->build($magazineUrl, $message->payloadToAnnounce);
$inboxes = array_filter($this->magazineRepository->findAudience($magazine), fn ($item) => null !== $item && $item !== $message->sourceInstance);
Expand Down
15 changes: 10 additions & 5 deletions src/MessageHandler/ActivityPub/Outbox/LikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ public function doWork(MessageInterface $message): void
$activity = $this->undoWrapper->build($activity);
}

$inboxes = array_filter(array_unique(array_merge(
$inboxes = array_merge(
$this->userRepository->findAudience($user),
$this->magazineRepository->findAudience($object->magazine),
[$object->user->apInboxUrl, $object->magazine->apId ? $object->magazine->apInboxUrl : null]
)));
$this->deliverManager->deliver($inboxes, $activity);
[$object->user->apInboxUrl],
);

if ('random' !== $object->magazine->name) {
// only add the magazine subscribers if it is not the random magazine
$inboxes = array_merge($inboxes, $this->magazineRepository->findAudience($object->magazine));
}

$this->deliverManager->deliver(array_filter(array_unique($inboxes)), $activity);
}
}
6 changes: 6 additions & 0 deletions src/MessageHandler/ActivityPub/Outbox/RemoveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public function doWork(MessageInterface $message): void
$actor = $this->userRepository->find($message->userActorId);
$removed = $this->userRepository->find($message->removedUserId);
$magazine = $this->magazineRepository->find($message->magazineId);

if ('random' === $magazine->name) {
// do not federate the random magazine
return;
}

if ($magazine->apId) {
$audience = [$magazine->apInboxUrl];
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/MessageHandler/ActivityPub/Outbox/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function doWork(MessageInterface $message): void
$activity = $this->updateWrapper->buildForActivity($entity, $editedByUser);

if ($entity instanceof Entry || $entity instanceof EntryComment || $entity instanceof Post || $entity instanceof PostComment) {
if ('random' === $entity->magazine->name) {
// do not federate the random magazine
return;
}

$inboxes = array_filter(array_unique(array_merge(
$this->userRepository->findAudience($entity->user),
$this->activityPubManager->createInboxesFromCC($activity, $entity->user),
Expand All @@ -82,6 +87,11 @@ public function doWork(MessageInterface $message): void
if ($entity instanceof User) {
$inboxes = $this->userRepository->findAudience($entity);
} elseif ($entity instanceof Magazine) {
if ('random' === $entity->name) {
// do not federate the random magazine
return;
}

if (null === $entity->apId) {
$inboxes = $this->magazineRepository->findAudience($entity);
if (null !== $editedByUser) {
Expand Down

0 comments on commit af60baa

Please sign in to comment.