Skip to content

Commit

Permalink
Fix Flag and Follow Activity handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich committed Oct 9, 2024
1 parent 1c6dbd7 commit 49bdeaa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Factory/ActivityPub/FlagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/MessageHandler/ActivityPub/Outbox/FlagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 9 additions & 2 deletions src/Service/ActivityPub/ActivityJsonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Service/ActivityPub/Wrapper/FollowWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 49bdeaa

Please sign in to comment.