Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Federate edits #940

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EventSubscriber/Entry/EntryPinSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function onEntryPin(EntryPinEvent $event): void
$activity = $this->addRemoveFactory->buildRemovePinnedPost($event->actor, $event->entry);
}
$this->logger->debug('dispatching announce for add pin post {e} by {u} in {m}', ['e' => $event->entry->title, 'u' => $event->actor->apId, 'm' => $event->entry->magazine->name]);
$this->bus->dispatch(new GenericAnnounceMessage($event->entry->magazine->getId(), $activity));
$this->bus->dispatch(new GenericAnnounceMessage($event->entry->magazine->getId(), $activity, $event->actor->apInboxUrl));
} else {
$this->logger->debug('entry {e} got {p} by {u}, dispatching new EntryPinMessage', ['e' => $event->entry->title, 'p' => $event->entry->sticky ? 'pinned' : 'unpinned', 'u' => $event->actor?->username ?? 'system']);
$this->bus->dispatch(new EntryPinMessage($event->entry->getId(), $event->entry->sticky, $event->actor?->getId()));
Expand Down
2 changes: 1 addition & 1 deletion src/Message/ActivityPub/Outbox/GenericAnnounceMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GenericAnnounceMessage implements ActivityPubOutboxInterface
{
public function __construct(public int $announcingMagazineId, public array $payloadToAnnounce)
public function __construct(public int $announcingMagazineId, public array $payloadToAnnounce, public ?string $sourceInstance)
{
}
}
39 changes: 20 additions & 19 deletions src/MessageHandler/ActivityPub/Inbox/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use App\Factory\PostCommentFactory;
use App\Factory\PostFactory;
use App\Message\ActivityPub\Inbox\UpdateMessage;
use App\Message\ActivityPub\Outbox\GenericAnnounceMessage;
use App\Message\Contracts\MessageInterface;
use App\MessageHandler\MbinMessageHandler;
use App\Repository\ApActivityRepository;
Expand All @@ -32,6 +33,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;

#[AsMessageHandler]
class UpdateHandler extends MbinMessageHandler
Expand All @@ -53,6 +55,7 @@ public function __construct(
private readonly ApObjectExtractor $objectExtractor,
private readonly MessageManager $messageManager,
private readonly LoggerInterface $logger,
private readonly MessageBusInterface $bus,
) {
parent::__construct($this->entityManager);
}
Expand Down Expand Up @@ -82,31 +85,29 @@ public function doWork(MessageInterface $message): void
}

$object = $this->entityManager->getRepository($object['type'])->find((int) $object['id']);

if (Entry::class === \get_class($object)) {
if ($object instanceof Entry) {
$this->editEntry($object, $actor);
} elseif (EntryComment::class === \get_class($object)) {
if (null === $object->magazine->apId) {
$this->bus->dispatch(new GenericAnnounceMessage($object->magazine->getId(), $message->payload, $actor->apInboxUrl));
}
} elseif ($object instanceof EntryComment) {
$this->editEntryComment($object, $actor);
} elseif (Post::class === \get_class($object)) {
if (null === $object->magazine->apId) {
$this->bus->dispatch(new GenericAnnounceMessage($object->magazine->getId(), $message->payload, $actor->apInboxUrl));
}
} elseif ($object instanceof Post) {
$this->editPost($object, $actor);
} elseif (PostComment::class === \get_class($object)) {
if (null === $object->magazine->apId) {
$this->bus->dispatch(new GenericAnnounceMessage($object->magazine->getId(), $message->payload, $actor->apInboxUrl));
}
} elseif ($object instanceof PostComment) {
$this->editPostComment($object, $actor);
} elseif (Message::class === \get_class($object)) {
if (null === $object->magazine->apId) {
$this->bus->dispatch(new GenericAnnounceMessage($object->magazine->getId(), $message->payload, $actor->apInboxUrl));
}
} elseif ($object instanceof Message) {
$this->editMessage($object, $actor);
}

// Dead-code introduced by Ernest "Temp disable handler dispatch", in commit:
// 4573e87f91923b9a5758e0dfacb3870d55ef1166
//
// if (null === $object->magazine->apId) {
// $this->bus->dispatch(
// new \App\Message\ActivityPub\Outbox\UpdateMessage(
// $actor->getId(),
// $object->getId(),
// get_class($object)
// )
// );
// }
}

private function editEntry(Entry $entry, User $user): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function doWork(MessageInterface $message): void
}
$magazineUrl = $this->urlGenerator->generate('ap_magazine', ['name' => $magazine->name], UrlGeneratorInterface::ABSOLUTE_URL);
$announce = $this->announceWrapper->build($magazineUrl, $message->payloadToAnnounce);
$inboxes = $this->magazineRepository->findAudience($magazine);
$inboxes = array_filter($this->magazineRepository->findAudience($magazine), fn ($item) => null !== $item && $item !== $message->sourceInstance);
$this->deliverManager->deliver($inboxes, $announce);
}
}
Loading