Skip to content

Commit

Permalink
Add testcase for hashtag matching (#1362)
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 Jan 13, 2025
1 parent 64f51e5 commit 8ead006
Show file tree
Hide file tree
Showing 37 changed files with 575 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ KBIN_DEFAULT_LANG=en
KBIN_DOMAIN=kbin.test
ELASTICSEARCH_ENABLED=false
KBIN_API_ITEMS_PER_PAGE=2
KBIN_FEDERATION_ENABLED=false
KBIN_FEDERATION_ENABLED=true

###> league/oauth2-server-bundle ###
OAUTH_PRIVATE_KEY=%kernel.project_dir%/config/oauth2/tests/private.pem
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ApImportObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Command;

use App\Message\ActivityPub\Inbox\ActivityMessage;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -21,7 +21,7 @@ class ApImportObject extends Command
{
public function __construct(
private readonly MessageBusInterface $bus,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
) {
parent::__construct();
}
Expand Down
13 changes: 10 additions & 3 deletions src/Controller/ActivityPub/WebFingerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@

use App\ActivityPub\JsonRd;
use App\Event\ActivityPub\WebfingerResponseEvent;
use App\Service\ActivityPub\Webfinger\WebFingerParameters;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class WebFingerController
{
public function __construct(private readonly EventDispatcherInterface $eventDispatcher)
{
public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly WebFingerParameters $webFingerParameters,
) {
}

public function __invoke(Request $request): JsonResponse
{
$event = new WebfingerResponseEvent(new JsonRd(), $request);
$event = new WebfingerResponseEvent(
new JsonRd(),
$request->query->get('resource') ?: '',
$this->webFingerParameters->getParams($request),
);
$this->eventDispatcher->dispatch($event);

if (!empty($event->jsonRd->getLinks())) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Entity\User;
use App\Message\ActivityPub\Inbox\CreateMessage;
use App\MessageHandler\ActivityPub\Inbox\CreateHandler;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPubManager;
use App\Service\SearchManager;
use App\Service\SettingsManager;
Expand All @@ -23,7 +23,7 @@ class SearchController extends AbstractController
public function __construct(
private readonly SearchManager $manager,
private readonly ActivityPubManager $activityPubManager,
private readonly ApHttpClient $apHttpClient,
private readonly ApHttpClientInterface $apHttpClient,
private readonly SubjectOverviewManager $overviewManager,
private readonly SettingsManager $settingsManager,
private readonly LoggerInterface $logger,
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Entity\Traits\CreatedAtTrait;
use App\Entity\Traits\VisibilityTrait;
use App\Repository\UserRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
Expand Down Expand Up @@ -869,7 +869,7 @@ public function hasMagazineOwnershipRequest(Magazine $magazine): bool
return $this->magazineOwnershipRequests->matching($criteria)->count() > 0;
}

public function getFollowerUrl(ApHttpClient $client, UrlGeneratorInterface $urlGenerator, bool $isRemote): ?string
public function getFollowerUrl(ApHttpClientInterface $client, UrlGeneratorInterface $urlGenerator, bool $isRemote): ?string
{
if ($isRemote) {
$actorObject = $client->getActorObject($this->apProfileId);
Expand Down
4 changes: 2 additions & 2 deletions src/Event/ActivityPub/WebfingerResponseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace App\Event\ActivityPub;

use App\ActivityPub\JsonRd;
use Symfony\Component\HttpFoundation\Request;

class WebfingerResponseEvent
{
public function __construct(
public JsonRd $jsonRd,
public Request $request,
public string $subject,
public array $params,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class GroupWebFingerProfileSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly WebFingerParameters $webfingerParameters,
private readonly MagazineRepository $magazineRepository,
private readonly UrlGeneratorInterface $urlGenerator,
) {
Expand All @@ -32,7 +31,7 @@ public static function getSubscribedEvents(): array

public function buildResponse(WebfingerResponseEvent $event): void
{
$params = $this->webfingerParameters->getParams($event->request);
$params = $event->params;
$jsonRd = $event->jsonRd;

if (
Expand Down
6 changes: 2 additions & 4 deletions src/EventSubscriber/ActivityPub/GroupWebFingerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class GroupWebFingerSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly WebFingerParameters $webfingerParameters,
private readonly MagazineRepository $magazineRepository,
private readonly UrlGeneratorInterface $urlGenerator,
) {
Expand All @@ -32,11 +31,10 @@ public static function getSubscribedEvents(): array

public function buildResponse(WebfingerResponseEvent $event): void
{
$request = $event->request;
$params = $this->webfingerParameters->getParams($request);
$params = $event->params;
$jsonRd = $event->jsonRd;

$subject = $request->query->get('resource') ?: '';
$subject = $event->subject;
if (!empty($subject)) {
$jsonRd->setSubject($subject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
class UserWebFingerProfileSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly WebFingerParameters $webfingerParameters,
private readonly UserRepository $userRepository,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly SettingsManager $settingsManager,
Expand All @@ -38,7 +37,7 @@ public static function getSubscribedEvents(): array

public function buildResponse(WebfingerResponseEvent $event): void
{
$params = $this->webfingerParameters->getParams($event->request);
$params = $event->params;
$jsonRd = $event->jsonRd;

if (isset($params[WebFingerParameters::ACCOUNT_KEY_NAME])) {
Expand Down
6 changes: 2 additions & 4 deletions src/EventSubscriber/ActivityPub/UserWebFingerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class UserWebFingerSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly WebFingerParameters $webfingerParameters,
private readonly UserRepository $userRepository,
private readonly UrlGeneratorInterface $urlGenerator,
) {
Expand All @@ -32,11 +31,10 @@ public static function getSubscribedEvents(): array

public function buildResponse(WebfingerResponseEvent $event): void
{
$request = $event->request;
$params = $this->webfingerParameters->getParams($request);
$params = $event->params;
$jsonRd = $event->jsonRd;

$subject = $request->query->get('resource') ?: '';
$subject = $event->subject;
if (!empty($subject)) {
$jsonRd->setSubject($subject);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActivityPub/EntryCommentNoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Entity\EntryComment;
use App\Markdown\MarkdownConverter;
use App\Markdown\RenderTarget;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\ContextsProvider;
use App\Service\ActivityPub\Wrapper\ImageWrapper;
use App\Service\ActivityPub\Wrapper\MentionsWrapper;
Expand All @@ -28,7 +28,7 @@ public function __construct(
private readonly MentionsWrapper $mentionsWrapper,
private readonly MentionManager $mentionManager,
private readonly EntryPageFactory $pageFactory,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly ActivityPubManager $activityPubManager,
private readonly MarkdownConverter $markdownConverter,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActivityPub/EntryPageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Entity\Entry;
use App\Markdown\MarkdownConverter;
use App\Markdown\RenderTarget;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\ContextsProvider;
use App\Service\ActivityPub\Wrapper\ImageWrapper;
use App\Service\ActivityPub\Wrapper\MentionsWrapper;
Expand All @@ -27,7 +27,7 @@ public function __construct(
private readonly ImageWrapper $imageWrapper,
private readonly TagsWrapper $tagsWrapper,
private readonly MentionsWrapper $mentionsWrapper,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly ActivityPubManager $activityPubManager,
private readonly MarkdownConverter $markdownConverter,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActivityPub/InstanceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace App\Factory\ActivityPub;

use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\ContextsProvider;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class InstanceFactory
{
public function __construct(
private string $kbinDomain,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly ContextsProvider $contextProvider,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActivityPub/PostCommentNoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Entity\PostComment;
use App\Markdown\MarkdownConverter;
use App\Markdown\RenderTarget;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\ContextsProvider;
use App\Service\ActivityPub\Wrapper\ImageWrapper;
use App\Service\ActivityPub\Wrapper\MentionsWrapper;
Expand All @@ -28,7 +28,7 @@ public function __construct(
private readonly TagsWrapper $tagsWrapper,
private readonly MentionsWrapper $mentionsWrapper,
private readonly MentionManager $mentionManager,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly ActivityPubManager $activityPubManager,
private readonly MarkdownConverter $markdownConverter,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActivityPub/PostNoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Entity\Post;
use App\Markdown\MarkdownConverter;
use App\Markdown\RenderTarget;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\ContextsProvider;
use App\Service\ActivityPub\Wrapper\ImageWrapper;
use App\Service\ActivityPub\Wrapper\MentionsWrapper;
Expand All @@ -27,7 +27,7 @@ public function __construct(
private readonly ImageWrapper $imageWrapper,
private readonly TagsWrapper $tagsWrapper,
private readonly MentionsWrapper $mentionsWrapper,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly ActivityPubManager $activityPubManager,
private readonly MentionManager $mentionManager,
private readonly TagExtractor $tagExtractor,
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use App\Message\Contracts\MessageInterface;
use App\MessageHandler\MbinMessageHandler;
use App\Repository\InstanceRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\SignatureValidator;
use App\Service\ActivityPubManager;
use App\Service\RemoteInstanceManager;
Expand All @@ -45,7 +45,7 @@ public function __construct(
private readonly SettingsManager $settingsManager,
private readonly MessageBusInterface $bus,
private readonly ActivityPubManager $activityPubManager,
private readonly ApHttpClient $apHttpClient,
private readonly ApHttpClientInterface $apHttpClient,
private readonly InstanceRepository $instanceRepository,
private readonly RemoteInstanceManager $remoteInstanceManager,
private readonly LoggerInterface $logger,
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Inbox/AddHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use App\Repository\ApActivityRepository;
use App\Repository\EntryRepository;
use App\Repository\MagazineRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPubManager;
use App\Service\EntryManager;
use App\Service\MagazineManager;
Expand All @@ -33,7 +33,7 @@ public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly ApHttpClient $apHttpClient,
private readonly ApHttpClientInterface $apHttpClient,
private readonly ApActivityRepository $apActivityRepository,
private readonly MagazineRepository $magazineRepository,
private readonly MagazineManager $magazineManager,
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use App\Message\Contracts\MessageInterface;
use App\MessageHandler\MbinMessageHandler;
use App\Repository\ApActivityRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\Note;
use App\Service\ActivityPub\Page;
use App\Service\SettingsManager;
Expand All @@ -37,7 +37,7 @@ public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly KernelInterface $kernel,
private readonly LoggerInterface $logger,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly MessageBusInterface $bus,
private readonly ApActivityRepository $repository,
private readonly Note $note,
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Inbox/FollowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Message\ActivityPub\Inbox\FollowMessage;
use App\Message\Contracts\MessageInterface;
use App\MessageHandler\MbinMessageHandler;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\Wrapper\FollowResponseWrapper;
use App\Service\ActivityPubManager;
use App\Service\MagazineManager;
Expand All @@ -28,7 +28,7 @@ public function __construct(
private readonly ActivityPubManager $activityPubManager,
private readonly UserManager $userManager,
private readonly MagazineManager $magazineManager,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly LoggerInterface $logger,
private readonly FollowResponseWrapper $followResponseWrapper,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Message\Contracts\MessageInterface;
use App\MessageHandler\MbinMessageHandler;
use App\Repository\InstanceRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPubManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
Expand All @@ -32,7 +32,7 @@ class DeliverHandler extends MbinMessageHandler
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly KernelInterface $kernel,
private readonly ApHttpClient $client,
private readonly ApHttpClientInterface $client,
private readonly ActivityPubManager $activityPubManager,
private readonly SettingsManager $settingsManager,
private readonly LoggerInterface $logger,
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ActivityPub/Outbox/FollowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\MessageHandler\MbinMessageHandler;
use App\Repository\MagazineRepository;
use App\Repository\UserRepository;
use App\Service\ActivityPub\ApHttpClient;
use App\Service\ActivityPub\ApHttpClientInterface;
use App\Service\ActivityPub\Wrapper\FollowWrapper;
use App\Service\ActivityPub\Wrapper\UndoWrapper;
use App\Service\ActivityPubManager;
Expand All @@ -30,7 +30,7 @@ public function __construct(
private readonly ActivityPubManager $activityPubManager,
private readonly FollowWrapper $followWrapper,
private readonly UndoWrapper $undoWrapper,
private readonly ApHttpClient $apHttpClient,
private readonly ApHttpClientInterface $apHttpClient,
private readonly SettingsManager $settingsManager,
private readonly DeliverManager $deliverManager,
) {
Expand Down
Loading

0 comments on commit 8ead006

Please sign in to comment.