diff --git a/src/Factory/ActivityPub/GroupFactory.php b/src/Factory/ActivityPub/GroupFactory.php index 74aa8159a..464989a08 100644 --- a/src/Factory/ActivityPub/GroupFactory.php +++ b/src/Factory/ActivityPub/GroupFactory.php @@ -5,6 +5,8 @@ namespace App\Factory\ActivityPub; use App\Entity\Magazine; +use App\Markdown\MarkdownConverter; +use App\Markdown\RenderTarget; use App\Service\ActivityPub\ContextsProvider; use App\Service\ImageManager; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -13,6 +15,7 @@ class GroupFactory { public function __construct( private readonly UrlGeneratorInterface $urlGenerator, + private readonly MarkdownConverter $markdownConverter, private readonly ContextsProvider $contextProvider, private readonly ImageManager $imageManager ) { @@ -20,6 +23,17 @@ public function __construct( public function create(Magazine $magazine): array { + $markdownSummary = $magazine->description; + + if (!empty($magazine->rules)) { + $markdownSummary .= "\r\n\r\n### Rules\r\n\r\n".$magazine->rules; + } + + $summary = $this->markdownConverter->convertToHtml( + $markdownSummary, + [MarkdownConverter::RENDER_TARGET => RenderTarget::ActivityPub], + ); + $group = [ 'type' => 'Group', '@context' => $this->contextProvider->referencedContexts(), @@ -47,7 +61,11 @@ public function create(Magazine $magazine): array 'id' => $this->getActivityPubId($magazine).'#main-key', 'publicKeyPem' => $magazine->publicKey, ], - 'summary' => $magazine->description, + 'summary' => $summary, + 'source' => $markdownSummary ? [ + 'content' => $markdownSummary, + 'mediaType' => 'text/markdown', + ] : null, 'sensitive' => $magazine->isAdult, 'attributedTo' => $this->urlGenerator->generate( 'ap_magazine_moderators', diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php index 452c4a41e..91bc49f56 100644 --- a/src/Service/ActivityPubManager.php +++ b/src/Service/ActivityPubManager.php @@ -29,6 +29,7 @@ use App\Repository\MagazineRepository; use App\Repository\UserRepository; use App\Service\ActivityPub\ApHttpClient; +use App\Service\ActivityPub\ApObjectExtractor; use App\Service\ActivityPub\Webfinger\WebFinger; use App\Service\ActivityPub\Webfinger\WebFingerFactory; use Doctrine\Common\Collections\Criteria; @@ -441,8 +442,7 @@ public function updateMagazine(string $actorUrl): ?Magazine if (isset($actor['endpoints']['sharedInbox']) || isset($actor['inbox'])) { if (isset($actor['summary'])) { - $converter = new HtmlConverter(['strip_tags' => true]); - $magazine->description = stripslashes($converter->convert($actor['summary'])); + $magazine->description = $this->extractMarkdownSummary($actor); } if (isset($actor['icon'])) { @@ -789,4 +789,15 @@ public function getEntityObject(string|array $apObject, array $fullPayload, call return $this->entityManager->getRepository($activity['type'])->find((int) $activity['id']); } + + public function extractMarkdownSummary(array $apObject): ?string + { + if (isset($apObject['source']) && isset($apObject['source']['mediaType']) && isset($apObject['source']['content']) && ApObjectExtractor::MARKDOWN_TYPE === $apObject['source']['mediaType']) { + return $apObject['source']['content']; + } else { + $converter = new HtmlConverter(['strip_tags' => true]); + + return stripslashes($converter->convert($apObject['summary'])); + } + } }