Browse Source

[CORE][Event] Make all events return \EventResult, enforced at container build time

v3
Hugo Sales 2 months ago
parent
commit
d4b7e990ce
Signed by: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
60 changed files with 345 additions and 239 deletions
  1. +6
    -5
      components/Attachment/Attachment.php
  2. +6
    -4
      components/Avatar/Avatar.php
  3. +5
    -4
      components/Circle/Circle.php
  4. +3
    -2
      components/Collection/Collection.php
  5. +3
    -2
      components/Collection/Util/MetaCollectionTrait.php
  6. +10
    -9
      components/Conversation/Conversation.php
  7. +2
    -1
      components/Feed/Feed.php
  8. +14
    -13
      components/FreeNetwork/FreeNetwork.php
  9. +6
    -5
      components/Group/Group.php
  10. +5
    -4
      components/Language/Language.php
  11. +3
    -2
      components/LeftPanel/LeftPanel.php
  12. +4
    -3
      components/Link/Link.php
  13. +6
    -5
      components/Notification/Notification.php
  14. +2
    -1
      components/Person/Person.php
  15. +4
    -3
      components/Posting/Posting.php
  16. +6
    -3
      components/Search/Search.php
  17. +3
    -2
      components/Subscription/Subscription.php
  18. +8
    -7
      components/Tag/Tag.php
  19. +3
    -0
      composer.json
  20. +1
    -1
      config/services.yaml
  21. +13
    -12
      plugins/ActivityPub/ActivityPub.php
  22. +3
    -2
      plugins/AttachmentCollections/AttachmentCollections.php
  23. +3
    -2
      plugins/AttachmentShowRelated/AttachmentShowRelated.php
  24. +4
    -3
      plugins/AudioEncoder/AudioEncoder.php
  25. +4
    -3
      plugins/Blog/Blog.php
  26. +5
    -4
      plugins/Cover/Cover.php
  27. +6
    -5
      plugins/DeleteNote/DeleteNote.php
  28. +4
    -3
      plugins/Directory/Directory.php
  29. +2
    -1
      plugins/EmailNotifications/EmailNotifications.php
  30. +7
    -6
      plugins/Embed/Embed.php
  31. +10
    -9
      plugins/Favourite/Favourite.php
  32. +3
    -2
      plugins/FileQuota/FileQuota.php
  33. +6
    -5
      plugins/ImageEncoder/ImageEncoder.php
  34. +3
    -2
      plugins/LatexNotes/LatexNotes.php
  35. +3
    -2
      plugins/MarkdownNotes/MarkdownNotes.php
  36. +5
    -4
      plugins/NoteTypeFeedFilter/NoteTypeFeedFilter.php
  37. +5
    -3
      plugins/OAuth2/OAuth2.php
  38. +4
    -3
      plugins/Oomox/Oomox.php
  39. +3
    -2
      plugins/Pinboard/Pinboard.php
  40. +10
    -9
      plugins/PinnedNotes/PinnedNotes.php
  41. +5
    -4
      plugins/Poll/Poll.php
  42. +4
    -3
      plugins/ProfileColor/ProfileColor.php
  43. +2
    -1
      plugins/RelatedTags/RelatedTags.php
  44. +10
    -9
      plugins/RepeatNote/RepeatNote.php
  45. +2
    -1
      plugins/StemWord/StemWord.php
  46. +3
    -2
      plugins/StoreRemoteMedia/StoreRemoteMedia.php
  47. +6
    -4
      plugins/TagBasedFiltering/TagBasedFiltering.php
  48. +4
    -2
      plugins/TreeNotes/TreeNotes.php
  49. +5
    -4
      plugins/UnboundGroup/UnboundGroup.php
  50. +6
    -5
      plugins/VideoEncoder/VideoEncoder.php
  51. +7
    -5
      plugins/WebHooks/WebHooks.php
  52. +6
    -5
      plugins/WebMonetization/WebMonetization.php
  53. +2
    -1
      plugins/XMPPNotifications/XMPPNotifications.php
  54. +20
    -20
      src/Core/Event.php
  55. +13
    -0
      src/Core/Event/EventResult.php
  56. +23
    -0
      src/Core/Event/GSEvent.php
  57. +11
    -4
      src/Core/ModuleManager.php
  58. +7
    -5
      src/Core/Modules/Module.php
  59. +2
    -1
      src/Core/Modules/Plugin.php
  60. +4
    -5
      src/Core/Security.php

+ 6
- 5
components/Attachment/Attachment.php View File

@@ -34,10 +34,11 @@ use Component\Attachment\Entity as E;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use EventResult;


class Attachment extends Component class Attachment extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('note_attachment_show', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}', [C\Attachment::class, 'attachmentShowWithNote']); $r->connect('note_attachment_show', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}', [C\Attachment::class, 'attachmentShowWithNote']);
$r->connect('note_attachment_view', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}/view', [C\Attachment::class, 'attachmentViewWithNote']); $r->connect('note_attachment_view', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}/view', [C\Attachment::class, 'attachmentViewWithNote']);
@@ -51,13 +52,13 @@ class Attachment extends Component
* *
* This can be used in the future to deduplicate images by visual content * This can be used in the future to deduplicate images by visual content
*/ */
public function onHashFile(string $filename, ?string &$out_hash): bool
public function onHashFile(string $filename, ?string &$out_hash): EventResult
{ {
$out_hash = hash_file(E\Attachment::FILEHASH_ALGO, $filename); $out_hash = hash_file(E\Attachment::FILEHASH_ALGO, $filename);
return Event::stop; return Event::stop;
} }


public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
{ {
Cache::delete("note-attachments-{$note->getId()}"); Cache::delete("note-attachments-{$note->getId()}");
foreach ($note->getAttachments() as $attachment) { foreach ($note->getAttachments() as $attachment) {
@@ -68,7 +69,7 @@ class Attachment extends Component
return Event::next; return Event::next;
} }


public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
{ {
if (!\in_array('attachment_to_note', $note_qb->getAllAliases())) { if (!\in_array('attachment_to_note', $note_qb->getAllAliases())) {
$note_qb->leftJoin( $note_qb->leftJoin(
@@ -84,7 +85,7 @@ class Attachment extends Component
/** /**
* Populate $note_expr with the criteria for looking for notes with attachments * Populate $note_expr with the criteria for looking for notes with attachments
*/ */
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
{ {
$include_term = str_contains($term, ':') ? explode(':', $term)[1] : $term; $include_term = str_contains($term, ':') ? explode(':', $term)[1] : $term;
if (Formatting::startsWith($term, ['note-types:', 'notes-incude:', 'note-filter:'])) { if (Formatting::startsWith($term, ['note-types:', 'notes-incude:', 'note-filter:'])) {


+ 6
- 4
components/Avatar/Avatar.php View File

@@ -32,15 +32,17 @@ use Component\Attachment\Entity\Attachment;
use Component\Attachment\Entity\AttachmentThumbnail; use Component\Attachment\Entity\AttachmentThumbnail;
use Component\Avatar\Controller as C; use Component\Avatar\Controller as C;
use Component\Avatar\Exception\NoAvatarException; use Component\Avatar\Exception\NoAvatarException;
use EventResult;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class Avatar extends Component class Avatar extends Component
{ {
public function onInitializeComponent()
public function onInitializeComponent(): EventResult
{ {
return EventResult::next;
} }


public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('avatar_actor', '/actor/{actor_id<\d+>}/avatar/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'avatar_view']); $r->connect('avatar_actor', '/actor/{actor_id<\d+>}/avatar/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'avatar_view']);
$r->connect('avatar_default', '/avatar/default/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'default_avatar_view']); $r->connect('avatar_default', '/avatar/default/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'default_avatar_view']);
@@ -51,7 +53,7 @@ class Avatar extends Component
/** /**
* @throws \App\Util\Exception\ClientException * @throws \App\Util\Exception\ClientException
*/ */
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): bool
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
{ {
if ($section === 'profile') { if ($section === 'profile') {
$tabs[] = [ $tabs[] = [
@@ -64,7 +66,7 @@ class Avatar extends Component
return Event::next; return Event::next;
} }


public function onAvatarUpdate(int $actor_id): bool
public function onAvatarUpdate(int $actor_id): EventResult
{ {
Cache::delete("avatar-{$actor_id}"); Cache::delete("avatar-{$actor_id}");
foreach (['full', 'big', 'medium', 'small'] as $size) { foreach (['full', 'big', 'medium', 'small'] as $size) {


+ 5
- 4
components/Circle/Circle.php View File

@@ -39,6 +39,7 @@ use Component\Circle\Entity\ActorCircleSubscription;
use Component\Circle\Entity\ActorTag; use Component\Circle\Entity\ActorTag;
use Component\Collection\Util\MetaCollectionTrait; use Component\Collection\Util\MetaCollectionTrait;
use Component\Tag\Tag; use Component\Tag\Tag;
use EventResult;
use Functional as F; use Functional as F;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


@@ -58,7 +59,7 @@ class Circle extends Component
protected const SLUG = 'circle'; protected const SLUG = 'circle';
protected const PLURAL_SLUG = 'circles'; protected const PLURAL_SLUG = 'circles';


public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('actor_circle_view_by_circle_id', '/circle/{circle_id<\d+>}', [CircleController\Circle::class, 'circleById']); $r->connect('actor_circle_view_by_circle_id', '/circle/{circle_id<\d+>}', [CircleController\Circle::class, 'circleById']);
// View circle members by (tagger id or nickname) and tag // View circle members by (tagger id or nickname) and tag
@@ -93,7 +94,7 @@ class Circle extends Component
]; ];
} }


public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
{ {
if ($section === 'profile' && \in_array($request->get('_route'), ['person_actor_settings', 'group_actor_settings'])) { if ($section === 'profile' && \in_array($request->get('_route'), ['person_actor_settings', 'group_actor_settings'])) {
$tabs[] = [ $tabs[] = [
@@ -106,7 +107,7 @@ class Circle extends Component
return Event::next; return Event::next;
} }


public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): bool
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult
{ {
$circles = $actor->getCircles(); $circles = $actor->getCircles();
foreach ($circles as $circle) { foreach ($circles as $circle) {
@@ -218,7 +219,7 @@ class Circle extends Component
return $ids_only ? array_map(fn ($x) => $x->getId(), $circles) : $circles; return $ids_only ? array_map(fn ($x) => $x->getId(), $circles) : $circles;
} }


public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
{ {
DB::persist(Feed::create([ DB::persist(Feed::create([
'actor_id' => $actor_id, 'actor_id' => $actor_id,


+ 3
- 2
components/Collection/Collection.php View File

@@ -14,6 +14,7 @@ use Component\Subscription\Entity\ActorSubscription;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use EventResult;


class Collection extends Component class Collection extends Component
{ {
@@ -64,7 +65,7 @@ class Collection extends Component
return ['notes' => $notes ?? null, 'actors' => $actors ?? null]; return ['notes' => $notes ?? null, 'actors' => $actors ?? null];
} }


public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
{ {
$note_aliases = $note_qb->getAllAliases(); $note_aliases = $note_qb->getAllAliases();
if (!\in_array('subscription', $note_aliases)) { if (!\in_array('subscription', $note_aliases)) {
@@ -80,7 +81,7 @@ class Collection extends Component
* Convert $term to $note_expr and $actor_expr, search criteria. Handles searching for text * Convert $term to $note_expr and $actor_expr, search criteria. Handles searching for text
* notes, for different types of actors and for the content of text notes * notes, for different types of actors and for the content of text notes
*/ */
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr)
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
{ {
if (str_contains($term, ':')) { if (str_contains($term, ':')) {
$term = explode(':', $term); $term = explode(':', $term);


+ 3
- 2
components/Collection/Util/MetaCollectionTrait.php View File

@@ -39,6 +39,7 @@ use App\Entity\Actor;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Formatting; use App\Util\Formatting;
use EventResult;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -94,7 +95,7 @@ trait MetaCollectionTrait
* It's compose of two forms: one to select collections to add * It's compose of two forms: one to select collections to add
* the current item to, and another to create a new collection. * the current item to, and another to create a new collection.
*/ */
public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult
{ {
$user = Common::actor(); $user = Common::actor();
if (\is_null($user)) { if (\is_null($user)) {
@@ -186,7 +187,7 @@ trait MetaCollectionTrait
return Event::next; return Event::next;
} }


public function onEndShowStyles(array &$styles, string $route): bool
public function onEndShowStyles(array &$styles, string $route): EventResult
{ {
$styles[] = 'components/Collection/assets/css/widget.css'; $styles[] = 'components/Collection/assets/css/widget.css';
$styles[] = 'components/Collection/assets/css/pages.css'; $styles[] = 'components/Collection/assets/css/pages.css';


+ 10
- 9
components/Conversation/Conversation.php View File

@@ -40,12 +40,13 @@ use App\Util\Common;
use App\Util\Formatting; use App\Util\Formatting;
use Component\Conversation\Entity\Conversation as ConversationEntity; use Component\Conversation\Entity\Conversation as ConversationEntity;
use Component\Conversation\Entity\ConversationMute; use Component\Conversation\Entity\ConversationMute;
use EventResult;
use Functional as F; use Functional as F;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class Conversation extends Component class Conversation extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('conversation', '/conversation/{conversation_id<\d+>}', [Controller\Conversation::class, 'showConversation']); $r->connect('conversation', '/conversation/{conversation_id<\d+>}', [Controller\Conversation::class, 'showConversation']);
$r->connect('conversation_mute', '/conversation/{conversation_id<\d+>}/mute', [Controller\Conversation::class, 'muteConversation']); $r->connect('conversation_mute', '/conversation/{conversation_id<\d+>}/mute', [Controller\Conversation::class, 'muteConversation']);
@@ -104,7 +105,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
public function onAddNoteActions(Request $request, Note $note, array &$actions): EventResult
{ {
if (\is_null(Common::user())) { if (\is_null(Common::user())) {
return Event::next; return Event::next;
@@ -144,7 +145,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onAppendCardNote(array $vars, array &$result): bool
public function onAppendCardNote(array $vars, array &$result): EventResult
{ {
if (str_contains($vars['request']->getPathInfo(), 'conversation')) { if (str_contains($vars['request']->getPathInfo(), 'conversation')) {
return Event::next; return Event::next;
@@ -197,7 +198,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): bool
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): EventResult
{ {
$to_note_id = $this->getReplyToIdFromRequest($request); $to_note_id = $this->getReplyToIdFromRequest($request);
if (!\is_null($to_note_id)) { if (!\is_null($to_note_id)) {
@@ -218,7 +219,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onPostingModifyData(Request $request, Actor $actor, array &$data): bool
public function onPostingModifyData(Request $request, Actor $actor, array &$data): EventResult
{ {
$to_note_id = $this->getReplyToIdFromRequest($request); $to_note_id = $this->getReplyToIdFromRequest($request);
if (!\is_null($to_note_id)) { if (!\is_null($to_note_id)) {
@@ -232,7 +233,7 @@ class Conversation extends Component
/** /**
* Add minimal Note card to RightPanel template * Add minimal Note card to RightPanel template
*/ */
public function onPrependPostingForm(Request $request, array &$elements): bool
public function onPrependPostingForm(Request $request, array &$elements): EventResult
{ {
$elements[] = Formatting::twigRenderFile('cards/blocks/note_compact_wrapper.html.twig', ['note' => Note::getById((int) $request->query->get('reply_to_id'))]); $elements[] = Formatting::twigRenderFile('cards/blocks/note_compact_wrapper.html.twig', ['note' => Note::getById((int) $request->query->get('reply_to_id'))]);
return Event::next; return Event::next;
@@ -247,7 +248,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
{ {
// Ensure we have the most up to date replies // Ensure we have the most up to date replies
Cache::delete(Note::cacheKeys($note->getId())['replies']); Cache::delete(Note::cacheKeys($note->getId())['replies']);
@@ -266,7 +267,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): bool
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): EventResult
{ {
if (\is_null($user = Common::user())) { if (\is_null($user = Common::user())) {
return Event::next; return Event::next;
@@ -302,7 +303,7 @@ class Conversation extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onNewNotificationShould(Activity $activity, Actor $actor): bool
public function onNewNotificationShould(Activity $activity, Actor $actor): EventResult
{ {
if ($activity->getObjectType() === 'note' && ConversationMute::isMuted($activity, $actor)) { if ($activity->getObjectType() === 'note' && ConversationMute::isMuted($activity, $actor)) {
return Event::stop; return Event::stop;


+ 2
- 1
components/Feed/Feed.php View File

@@ -27,10 +27,11 @@ use App\Core\Event;
use App\Core\Modules\Component; use App\Core\Modules\Component;
use App\Core\Router; use App\Core\Router;
use Component\Feed\Controller as C; use Component\Feed\Controller as C;
use EventResult;


class Feed extends Component class Feed extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']); $r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']);
$r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']); $r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']);


+ 14
- 13
components/FreeNetwork/FreeNetwork.php View File

@@ -54,6 +54,7 @@ use Component\FreeNetwork\Util\WebfingerResource;
use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceActor; use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceActor;
use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceNote; use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceNote;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use EventResult;
use Exception; use Exception;
use const PREG_SET_ORDER; use const PREG_SET_ORDER;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@@ -79,13 +80,13 @@ class FreeNetwork extends Component
public const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize'; public const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize';
private static array $protocols = []; private static array $protocols = [];


public function onInitializeComponent(): bool
public function onInitializeComponent(): EventResult
{ {
Event::handle('AddFreeNetworkProtocol', [&self::$protocols]); Event::handle('AddFreeNetworkProtocol', [&self::$protocols]);
return Event::next; return Event::next;
} }


public function onAddRoute(Router $m): bool
public function onAddRoute(Router $m): EventResult
{ {
// Feeds // Feeds
$m->connect('feed_network', '/feed/network', [Feeds::class, 'network']); $m->connect('feed_network', '/feed/network', [Feeds::class, 'network']);
@@ -111,7 +112,7 @@ class FreeNetwork extends Component
return Event::next; return Event::next;
} }


public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
{ {
DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_network'), 'route' => $route, 'title' => _m('Meteorites'), 'ordering' => $ordering++])); DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_network'), 'route' => $route, 'title' => _m('Meteorites'), 'ordering' => $ordering++]));
DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_clique'), 'route' => $route, 'title' => _m('Planetary System'), 'ordering' => $ordering++])); DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_clique'), 'route' => $route, 'title' => _m('Planetary System'), 'ordering' => $ordering++]));
@@ -119,7 +120,7 @@ class FreeNetwork extends Component
return Event::next; return Event::next;
} }


public function onStartGetProfileAcctUri(Actor $profile, &$acct): bool
public function onStartGetProfileAcctUri(Actor $profile, &$acct): EventResult
{ {
$wfr = new WebFingerResourceActor($profile); $wfr = new WebFingerResourceActor($profile);
try { try {
@@ -147,7 +148,7 @@ class FreeNetwork extends Component
* @throws NoSuchActorException * @throws NoSuchActorException
* @throws ServerException * @throws ServerException
*/ */
public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): bool
public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): EventResult
{ {
// * Either we didn't find the profile, then we want to make // * Either we didn't find the profile, then we want to make
// the $profile variable null for clarity. // the $profile variable null for clarity.
@@ -223,7 +224,7 @@ class FreeNetwork extends Component
return Event::next; return Event::next;
} }


public function onStartHostMetaLinks(array &$links): bool
public function onStartHostMetaLinks(array &$links): EventResult
{ {
foreach (Discovery::supportedMimeTypes() as $type) { foreach (Discovery::supportedMimeTypes() as $type) {
$links[] = new XML_XRD_Element_Link( $links[] = new XML_XRD_Element_Link(
@@ -244,7 +245,7 @@ class FreeNetwork extends Component
/** /**
* Add a link header for LRDD Discovery * Add a link header for LRDD Discovery
*/ */
public function onStartShowHTML($action): bool
public function onStartShowHTML($action): EventResult
{ {
if ($action instanceof ShowstreamAction) { if ($action instanceof ShowstreamAction) {
$resource = $action->getTarget()->getUri(); $resource = $action->getTarget()->getUri();
@@ -257,13 +258,13 @@ class FreeNetwork extends Component
return Event::next; return Event::next;
} }


public function onStartDiscoveryMethodRegistration(Discovery $disco): bool
public function onStartDiscoveryMethodRegistration(Discovery $disco): EventResult
{ {
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodWebfinger'); $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodWebfinger');
return Event::next; return Event::next;
} }


public function onEndDiscoveryMethodRegistration(Discovery $disco): bool
public function onEndDiscoveryMethodRegistration(Discovery $disco): EventResult
{ {
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodHostMeta'); $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodHostMeta');
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodLinkHeader'); $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodLinkHeader');
@@ -275,7 +276,7 @@ class FreeNetwork extends Component
* @throws ClientException * @throws ClientException
* @throws ServerException * @throws ServerException
*/ */
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?Response &$response = null): bool
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?Response &$response = null): EventResult
{ {
if (!\in_array($route, ['freenetwork_hostmeta', 'freenetwork_hostmeta_format', 'freenetwork_webfinger', 'freenetwork_webfinger_format', 'freenetwork_ownerxrd'])) { if (!\in_array($route, ['freenetwork_hostmeta', 'freenetwork_hostmeta_format', 'freenetwork_webfinger', 'freenetwork_webfinger_format', 'freenetwork_ownerxrd'])) {
return Event::next; return Event::next;
@@ -376,7 +377,7 @@ class FreeNetwork extends Component
* @return bool hook return value * @return bool hook return value
* @example.com/mublog/user * @example.com/mublog/user
*/ */
public function onEndFindMentions(Actor $sender, string $text, array &$mentions): bool
public function onEndFindMentions(Actor $sender, string $text, array &$mentions): EventResult
{ {
$matches = []; $matches = [];


@@ -517,7 +518,7 @@ class FreeNetwork extends Component
* Add fediverse: query expression * Add fediverse: query expression
* // TODO: adding WebFinger would probably be nice * // TODO: adding WebFinger would probably be nice
*/ */
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
{ {
if (Formatting::startsWith($term, ['fediverse:'])) { if (Formatting::startsWith($term, ['fediverse:'])) {
foreach (self::$protocols as $protocol) { foreach (self::$protocols as $protocol) {
@@ -530,7 +531,7 @@ class FreeNetwork extends Component
return Event::next; return Event::next;
} }


public function onPluginVersion(array &$versions): bool
public function onPluginVersion(array &$versions): EventResult
{ {
$versions[] = [ $versions[] = [
'name' => 'WebFinger', 'name' => 'WebFinger',


+ 6
- 5
components/Group/Group.php View File

@@ -33,11 +33,12 @@ use App\Util\Nickname;
use Component\Group\Controller as C; use Component\Group\Controller as C;
use Component\Group\Entity\LocalGroup; use Component\Group\Entity\LocalGroup;
use Component\Notification\Notification; use Component\Notification\Notification;
use EventResult;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class Group extends Component class Group extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']); $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']);
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']); $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']);
@@ -50,7 +51,7 @@ class Group extends Component
* Enqueues a notification for an Actor (such as person or group) which means * Enqueues a notification for an Actor (such as person or group) which means
* it shows up in their home feed and such. * it shows up in their home feed and such.
*/ */
public function onNewNotificationStart(Actor $sender, Activity $activity, array $targets = [], ?string $reason = null): bool
public function onNewNotificationStart(Actor $sender, Activity $activity, array $targets = [], ?string $reason = null): EventResult
{ {
foreach ($targets as $target) { foreach ($targets as $target) {
if ($target->isGroup()) { if ($target->isGroup()) {
@@ -70,7 +71,7 @@ class Group extends Component
/** /**
* Add an <a href=group_actor_settings> to the profile card for groups, if the current actor can access them * Add an <a href=group_actor_settings> to the profile card for groups, if the current actor can access them
*/ */
public function onAppendCardProfile(array $vars, array &$res): bool
public function onAppendCardProfile(array $vars, array &$res): EventResult
{ {
$actor = Common::actor(); $actor = Common::actor();
$group = $vars['actor']; $group = $vars['actor'];
@@ -108,7 +109,7 @@ class Group extends Component
return null; return null;
} }


public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): bool
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult
{ {
$group = $this->getGroupFromContext($request); $group = $this->getGroupFromContext($request);
if (!\is_null($group)) { if (!\is_null($group)) {
@@ -127,7 +128,7 @@ class Group extends Component
* *
* @param null|Actor $context_actor Actor group, if current route is part of an existing Group set of routes * @param null|Actor $context_actor Actor group, if current route is part of an existing Group set of routes
*/ */
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): bool
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): EventResult
{ {
$ctx = $this->getGroupFromContext($request); $ctx = $this->getGroupFromContext($request);
if (!\is_null($ctx)) { if (!\is_null($ctx)) {


+ 5
- 4
components/Language/Language.php View File

@@ -33,18 +33,19 @@ use Component\Language\Entity\ActorLanguage;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use EventResult;
use Functional as F; use Functional as F;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class Language extends Component class Language extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('settings_sort_languages', '/settings/sort_languages', [C\Language::class, 'sortLanguages']); $r->connect('settings_sort_languages', '/settings/sort_languages', [C\Language::class, 'sortLanguages']);
return Event::next; return Event::next;
} }


public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): EventResult
{ {
if (\is_null($actor)) { if (\is_null($actor)) {
return Event::next; return Event::next;
@@ -60,7 +61,7 @@ class Language extends Component
/** /**
* Populate $note_expr or $actor_expr with an expression to match a language * Populate $note_expr or $actor_expr with an expression to match a language
*/ */
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
{ {
$search_term = str_contains($term, ':') ? explode(':', $term)[1] : $term; $search_term = str_contains($term, ':') ? explode(':', $term)[1] : $term;


@@ -103,7 +104,7 @@ class Language extends Component
return Event::next; return Event::next;
} }


public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
{ {
$note_aliases = $note_qb->getAllAliases(); $note_aliases = $note_qb->getAllAliases();
if (!\in_array('note_language', $note_aliases)) { if (!\in_array('note_language', $note_aliases)) {


+ 3
- 2
components/LeftPanel/LeftPanel.php View File

@@ -32,10 +32,11 @@ use App\Entity\Feed;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use Component\LeftPanel\Controller as C; use Component\LeftPanel\Controller as C;
use EventResult;


class LeftPanel extends Component class LeftPanel extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('edit_feeds', '/edit-feeds', C\EditFeeds::class); $r->connect('edit_feeds', '/edit-feeds', C\EditFeeds::class);
return Event::next; return Event::next;
@@ -46,7 +47,7 @@ class LeftPanel extends Component
* @throws \App\Util\Exception\ServerException * @throws \App\Util\Exception\ServerException
* @throws ClientException * @throws ClientException
*/ */
public function onAppendFeed(Actor $actor, string $title, string $route, array $route_params): bool
public function onAppendFeed(Actor $actor, string $title, string $route, array $route_params): EventResult
{ {
$cache_key = Feed::cacheKey($actor); $cache_key = Feed::cacheKey($actor);
$feeds = Feed::getFeeds($actor); $feeds = Feed::getFeeds($actor);


+ 4
- 3
components/Link/Link.php View File

@@ -31,6 +31,7 @@ use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\HTML; use App\Util\HTML;
use Component\Link\Entity\NoteToLink; use Component\Link\Entity\NoteToLink;
use EventResult;
use InvalidArgumentException; use InvalidArgumentException;


class Link extends Component class Link extends Component
@@ -54,7 +55,7 @@ class Link extends Component
/** /**
* Extract URLs from $content and create the appropriate Link and NoteToLink entities * Extract URLs from $content and create the appropriate Link and NoteToLink entities
*/ */
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $process_note_content_extra_args = []): bool
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $process_note_content_extra_args = []): EventResult
{ {
$ignore = $process_note_content_extra_args['ignoreLinks'] ?? []; $ignore = $process_note_content_extra_args['ignoreLinks'] ?? [];
if (Common::config('attachments', 'process_links')) { if (Common::config('attachments', 'process_links')) {
@@ -71,7 +72,7 @@ class Link extends Component
return Event::next; return Event::next;
} }


public function onRenderPlainTextNoteContent(string &$text): bool
public function onRenderPlainTextNoteContent(string &$text): EventResult
{ {
$text = $this->replaceURLs($text); $text = $this->replaceURLs($text);
return Event::next; return Event::next;
@@ -275,7 +276,7 @@ class Link extends Component
return HTML::html(['a' => ['attrs' => $attrs, $url]], options: ['indent' => false]); return HTML::html(['a' => ['attrs' => $attrs, $url]], options: ['indent' => false]);
} }


public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
{ {
DB::wrapInTransaction(fn () => NoteToLink::removeWhereNoteId($note->getId())); DB::wrapInTransaction(fn () => NoteToLink::removeWhereNoteId($note->getId()));
return Event::next; return Event::next;


+ 6
- 5
components/Notification/Notification.php View File

@@ -34,12 +34,13 @@ use App\Entity\LocalUser;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\FreeNetwork\FreeNetwork; use Component\FreeNetwork\FreeNetwork;
use Component\Notification\Controller\Feed; use Component\Notification\Controller\Feed;
use EventResult;
use Exception; use Exception;
use Throwable; use Throwable;


class Notification extends Component class Notification extends Component
{ {
public function onAddRoute(Router $m): bool
public function onAddRoute(Router $m): EventResult
{ {
$m->connect('feed_notifications', '/feed/notifications', [Feed::class, 'notifications']); $m->connect('feed_notifications', '/feed/notifications', [Feed::class, 'notifications']);
return Event::next; return Event::next;
@@ -48,7 +49,7 @@ class Notification extends Component
/** /**
* @throws ServerException * @throws ServerException
*/ */
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): bool
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
{ {
DB::persist(\App\Entity\Feed::create([ DB::persist(\App\Entity\Feed::create([
'actor_id' => $actor_id, 'actor_id' => $actor_id,
@@ -75,7 +76,7 @@ class Notification extends Component
* @param array $targets Attentions, Mentions, any other source. Should never be empty, you usually want to register an attention to every $sender->getSubscribers() * @param array $targets Attentions, Mentions, any other source. Should never be empty, you usually want to register an attention to every $sender->getSubscribers()
* @param null|string $reason An optional reason explaining why this notification exists * @param null|string $reason An optional reason explaining why this notification exists
*/ */
public function onNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
public function onNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): EventResult
{ {
// Ensure targets are all actor objects and unique // Ensure targets are all actor objects and unique
$effective_targets = []; $effective_targets = [];
@@ -102,13 +103,13 @@ class Notification extends Component
return Event::next; return Event::next;
} }


public function onQueueNotificationLocal(Actor $sender, Activity $activity, Actor $target, ?string $reason, array &$retry_args): bool
public function onQueueNotificationLocal(Actor $sender, Activity $activity, Actor $target, ?string $reason, array &$retry_args): EventResult
{ {
// TODO: use https://symfony.com/doc/current/notifier.html // TODO: use https://symfony.com/doc/current/notifier.html
return Event::stop; return Event::stop;
} }


public function onQueueNotificationRemote(Actor $sender, Activity $activity, array $targets, ?string $reason, array &$retry_args): bool
public function onQueueNotificationRemote(Actor $sender, Activity $activity, array $targets, ?string $reason, array &$retry_args): EventResult
{ {
if (FreeNetwork::notify($sender, $activity, $targets, $reason)) { if (FreeNetwork::notify($sender, $activity, $targets, $reason)) {
return Event::stop; return Event::stop;


+ 2
- 1
components/Person/Person.php View File

@@ -26,10 +26,11 @@ use App\Core\Modules\Component;
use App\Core\Router; use App\Core\Router;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Person\Controller as C; use Component\Person\Controller as C;
use EventResult;


class Person extends Component class Person extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect(id: 'person_actor_view_id', uri_path: '/person/{id<\d+>}', target: [C\PersonFeed::class, 'personViewId']); $r->connect(id: 'person_actor_view_id', uri_path: '/person/{id<\d+>}', target: [C\PersonFeed::class, 'personViewId']);
$r->connect(id: 'person_actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\PersonFeed::class, 'personViewNickname'], options: ['is_system_path' => false]); $r->connect(id: 'person_actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\PersonFeed::class, 'personViewNickname'], options: ['is_system_path' => false]);


+ 4
- 3
components/Posting/Posting.php View File

@@ -47,6 +47,7 @@ use Component\Attachment\Entity\AttachmentToNote;
use Component\Conversation\Conversation; use Component\Conversation\Conversation;
use Component\Language\Entity\Language; use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention; use Component\Notification\Entity\Attention;
use EventResult;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


@@ -54,7 +55,7 @@ class Posting extends Component
{ {
public const route = 'posting_form_action'; public const route = 'posting_form_action';


public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect(self::route, '/form/posting', Controller\Posting::class); $r->connect(self::route, '/form/posting', Controller\Posting::class);
return Event::next; return Event::next;
@@ -70,7 +71,7 @@ class Posting extends Component
* @throws RedirectException * @throws RedirectException
* @throws ServerException * @throws ServerException
*/ */
public function onAddMainRightPanelBlock(Request $request, array &$res): bool
public function onAddMainRightPanelBlock(Request $request, array &$res): EventResult
{ {
if (\is_null($user = Common::user()) || preg_match('(feed|conversation|group|view)', $request->get('_route')) === 0) { if (\is_null($user = Common::user()) || preg_match('(feed|conversation|group|view)', $request->get('_route')) === 0) {
return Event::next; return Event::next;
@@ -298,7 +299,7 @@ class Posting extends Component
return [$activity, $note, $effective_attentions]; return [$activity, $note, $effective_attentions];
} }


public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = [])
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = []): EventResult
{ {
switch ($content_type) { switch ($content_type) {
case 'text/plain': case 'text/plain':


+ 6
- 3
components/Search/Search.php View File

@@ -27,10 +27,12 @@ use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Modules\Component; use App\Core\Modules\Component;
use App\Core\Router;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Formatting; use App\Util\Formatting;
use EventResult;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
@@ -39,9 +41,10 @@ use Symfony\Component\HttpFoundation\Request;


class Search extends Component class Search extends Component
{ {
public function onAddRoute($r)
public function onAddRoute(Router $r): EventResult
{ {
$r->connect('search', '/search', Controller\Search::class); $r->connect('search', '/search', Controller\Search::class);
return EventResult::next;
} }


/** /**
@@ -133,7 +136,7 @@ class Search extends Component
* *
* @throws RedirectException * @throws RedirectException
*/ */
public function onPrependRightPanelBlock(Request $request, array &$elements): bool
public function onPrependRightPanelBlock(Request $request, array &$elements): EventResult
{ {
$elements[] = Formatting::twigRenderFile('cards/search/view.html.twig', ['search' => self::searchForm($request)]); $elements[] = Formatting::twigRenderFile('cards/search/view.html.twig', ['search' => self::searchForm($request)]);
return Event::next; return Event::next;
@@ -146,7 +149,7 @@ class Search extends Component
* *
* @return bool hook value; true means continue processing, false means stop * @return bool hook value; true means continue processing, false means stop
*/ */
public function onEndShowStyles(array &$styles, string $route): bool
public function onEndShowStyles(array &$styles, string $route): EventResult
{ {
$styles[] = 'components/Search/assets/css/view.css'; $styles[] = 'components/Search/assets/css/view.css';
return Event::next; return Event::next;


+ 3
- 2
components/Subscription/Subscription.php View File

@@ -39,11 +39,12 @@ use App\Util\Exception\ServerException;
use Component\Notification\Entity\Attention; use Component\Notification\Entity\Attention;
use Component\Subscription\Controller\Subscribers as SubscribersController; use Component\Subscription\Controller\Subscribers as SubscribersController;
use Component\Subscription\Controller\Subscriptions as SubscriptionsController; use Component\Subscription\Controller\Subscriptions as SubscriptionsController;
use EventResult;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class Subscription extends Component class Subscription extends Component
{ {
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect(id: 'actor_subscribe_add', uri_path: '/actor/subscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersAdd']); $r->connect(id: 'actor_subscribe_add', uri_path: '/actor/subscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersAdd']);
$r->connect(id: 'actor_subscribe_remove', uri_path: '/actor/unsubscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersRemove']); $r->connect(id: 'actor_subscribe_remove', uri_path: '/actor/unsubscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersRemove']);
@@ -186,7 +187,7 @@ class Subscription extends Component
* *
* @return bool EventHook * @return bool EventHook
*/ */
public function onAddProfileActions(Request $request, Actor $object, array &$actions): bool
public function onAddProfileActions(Request $request, Actor $object, array &$actions): EventResult
{ {
// Action requires a user to be logged in // Action requires a user to be logged in
// We know it's a LocalUser, which has the same id as Actor // We know it's a LocalUser, which has the same id as Actor


+ 8
- 7
components/Tag/Tag.php View File

@@ -42,6 +42,7 @@ use Component\Tag\Entity\NoteTag;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use EventResult;
use Functional as F; use Functional as F;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -60,7 +61,7 @@ class Tag extends Component
public const TAG_REGEX = '/(^|\\s)(#[\\pL\\pN_\\-]{1,64})/u'; // Brion Vibber 2011-02-23 v2:classes/Notice.php:367 function saveTags public const TAG_REGEX = '/(^|\\s)(#[\\pL\\pN_\\-]{1,64})/u'; // Brion Vibber 2011-02-23 v2:classes/Notice.php:367 function saveTags
public const TAG_SLUG_REGEX = '[A-Za-z0-9]{1,64}'; public const TAG_SLUG_REGEX = '[A-Za-z0-9]{1,64}';


public function onAddRoute($r): bool
public function onAddRoute($r): EventResult
{ {
$r->connect('single_note_tag', '/note-tag/{tag<' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'single_note_tag']); $r->connect('single_note_tag', '/note-tag/{tag<' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'single_note_tag']);
$r->connect('multi_note_tags', '/note-tags/{tags<(' . self::TAG_SLUG_REGEX . ',)+' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'multi_note_tags']); $r->connect('multi_note_tags', '/note-tags/{tags<(' . self::TAG_SLUG_REGEX . ',)+' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'multi_note_tags']);
@@ -118,7 +119,7 @@ class Tag extends Component
/** /**
* Process note by extracting any tags present * Process note by extracting any tags present
*/ */
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $extra_args): bool
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $extra_args): EventResult
{ {
if ($extra_args['TagProcessed'] ?? false) { if ($extra_args['TagProcessed'] ?? false) {
return Event::next; return Event::next;
@@ -135,7 +136,7 @@ class Tag extends Component
return Event::next; return Event::next;
} }


public function onRenderPlainTextNoteContent(string &$text, ?string $locale = null): bool
public function onRenderPlainTextNoteContent(string &$text, ?string $locale = null): EventResult
{ {
$text = preg_replace_callback(self::TAG_REGEX, fn ($m) => $m[1] . self::tagLink($m[2], $locale), $text); $text = preg_replace_callback(self::TAG_REGEX, fn ($m) => $m[1] . self::tagLink($m[2], $locale), $text);
return Event::next; return Event::next;
@@ -213,7 +214,7 @@ class Tag extends Component
* *
* $term /^(note|tag|people|actor)/ means we want to match only either a note or an actor * $term /^(note|tag|people|actor)/ means we want to match only either a note or an actor
*/ */
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
{ {
if (!str_contains($term, ':')) { if (!str_contains($term, ':')) {
return Event::next; return Event::next;
@@ -252,7 +253,7 @@ class Tag extends Component
return Event::next; return Event::next;
} }


public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
{ {
if (!\in_array('note_tag', $note_qb->getAllAliases())) { if (!\in_array('note_tag', $note_qb->getAllAliases())) {
$note_qb->leftJoin(NoteTag::class, 'note_tag', Expr\Join::WITH, 'note_tag.note_id = note.id'); $note_qb->leftJoin(NoteTag::class, 'note_tag', Expr\Join::WITH, 'note_tag.note_id = note.id');
@@ -263,13 +264,13 @@ class Tag extends Component
return Event::next; return Event::next;
} }


public function onPostingAddFormEntries(Request $request, Actor $actor, array &$form_params): bool
public function onPostingAddFormEntries(Request $request, Actor $actor, array &$form_params): EventResult
{ {
$form_params[] = ['tag_use_canonical', CheckboxType::class, ['required' => false, 'data' => true, 'label' => _m('Make note tags canonical'), 'help' => _m('Canonical tags will be treated as a version of an existing tag with the same root/stem (e.g. \'#great_tag\' will be considered as a version of \'#great\', if it already exists)')]]; $form_params[] = ['tag_use_canonical', CheckboxType::class, ['required' => false, 'data' => true, 'label' => _m('Make note tags canonical'), 'help' => _m('Canonical tags will be treated as a version of an existing tag with the same root/stem (e.g. \'#great_tag\' will be considered as a version of \'#great\', if it already exists)')]];
return Event::next; return Event::next;
} }


public function onAddExtraArgsToNoteContent(Request $request, Actor $actor, array $data, array &$extra_args): bool
public function onAddExtraArgsToNoteContent(Request $request, Actor $actor, array $data, array &$extra_args): EventResult
{ {
if (!isset($data['tag_use_canonical'])) { if (!isset($data['tag_use_canonical'])) {
throw new ClientException(_m('Missing Use Canonical preference for Tags.')); throw new ClientException(_m('Missing Use Canonical preference for Tags.'));


+ 3
- 0
composer.json View File

@@ -103,6 +103,9 @@
"files": [ "files": [
"src/Core/I18n/I18n.php" "src/Core/I18n/I18n.php"
], ],
"classmap": [
"src/Core/Event/EventResult.php"
],
"psr-4": { "psr-4": {
"App\\": "src/", "App\\": "src/",
"Plugin\\": "plugins/", "Plugin\\": "plugins/",


+ 1
- 1
config/services.yaml View File

@@ -13,7 +13,7 @@ services:
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name
App\: App\:
resource: '../src/*' resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Routes}'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Routes,Core/Event/EventResult.php}'


App\Test\Fixtures\: App\Test\Fixtures\:
resource: '../tests/fixtures/*' resource: '../tests/fixtures/*'


+ 13
- 12
plugins/ActivityPub/ActivityPub.php View File

@@ -50,6 +50,7 @@ use App\Util\Exception\BugFoundException;
use Component\Collection\Util\Controller\OrderedCollection; use Component\Collection\Util\Controller\OrderedCollection;
use Component\FreeNetwork\Entity\FreeNetworkActorProtocol; use Component\FreeNetwork\Entity\FreeNetworkActorProtocol;
use Component\FreeNetwork\Util\Discovery; use Component\FreeNetwork\Util\Discovery;
use EventResult;
use Exception; use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use Plugin\ActivityPub\Controller\Inbox; use Plugin\ActivityPub\Controller\Inbox;
@@ -122,14 +123,14 @@ class ActivityPub extends Plugin
], ],
]; ];


public function onInitializePlugin(): bool
public function onInitializePlugin(): EventResult
{ {
Event::handle('ActivityStreamsTwoContext', [&self::$activity_streams_two_context]); Event::handle('ActivityStreamsTwoContext', [&self::$activity_streams_two_context]);
self::$activity_streams_two_context = array_unique(self::$activity_streams_two_context, \SORT_REGULAR); self::$activity_streams_two_context = array_unique(self::$activity_streams_two_context, \SORT_REGULAR);
return Event::next; return Event::next;
} }


public function onQueueActivitypubInbox(ActivitypubActor $ap_actor, Actor $actor, string|AbstractObject $type): bool
public function onQueueActivitypubInbox(ActivitypubActor $ap_actor, Actor $actor, string|AbstractObject $type): EventResult
{ {
// TODO: Check if Actor has authority over payload // TODO: Check if Actor has authority over payload


@@ -157,7 +158,7 @@ class ActivityPub extends Plugin
* *
* @param Router $r the router that was initialized * @param Router $r the router that was initialized
*/ */
public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
$r->connect( $r->connect(
'activitypub_inbox', 'activitypub_inbox',
@@ -183,7 +184,7 @@ class ActivityPub extends Plugin
/** /**
* Fill Actor->getUrl() calls with correct URL coming from ActivityPub * Fill Actor->getUrl() calls with correct URL coming from ActivityPub
*/ */
public function onStartGetActorUri(Actor $actor, int $type, ?string &$url): bool
public function onStartGetActorUri(Actor $actor, int $type, ?string &$url): EventResult
{ {
if ( if (
// Is remote? // Is remote?
@@ -203,7 +204,7 @@ class ActivityPub extends Plugin
/** /**
* Fill Actor->canAdmin() for Actors that came from ActivityPub * Fill Actor->canAdmin() for Actors that came from ActivityPub
*/ */
public function onFreeNetworkActorCanAdmin(Actor $actor, Actor $other, bool &$canAdmin): bool
public function onFreeNetworkActorCanAdmin(Actor $actor, Actor $other, bool &$canAdmin): EventResult
{ {
// Are both in AP? // Are both in AP?
if ( if (
@@ -223,7 +224,7 @@ class ActivityPub extends Plugin
* *
* @throws Exception * @throws Exception
*/ */
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?TypeResponse &$response = null): bool
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?TypeResponse &$response = null): EventResult
{ {
if (\count(array_intersect(self::$accept_headers, $accept_header)) === 0) { if (\count(array_intersect(self::$accept_headers, $accept_header)) === 0) {
return Event::next; return Event::next;
@@ -262,7 +263,7 @@ class ActivityPub extends Plugin
/** /**
* Add ActivityStreams 2 Extensions * Add ActivityStreams 2 Extensions
*/ */
public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): bool
public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): EventResult
{ {
switch ($type_name) { switch ($type_name) {
case 'Person': case 'Person':
@@ -280,7 +281,7 @@ class ActivityPub extends Plugin
/** /**
* Let FreeNetwork Component know we exist and which class to use to call the freeNetworkDistribute method * Let FreeNetwork Component know we exist and which class to use to call the freeNetworkDistribute method
*/ */
public function onAddFreeNetworkProtocol(array &$protocols): bool
public function onAddFreeNetworkProtocol(array &$protocols): EventResult
{ {
$protocols[] = '\Plugin\ActivityPub\ActivityPub'; $protocols[] = '\Plugin\ActivityPub\ActivityPub';
return Event::next; return Event::next;
@@ -321,7 +322,7 @@ class ActivityPub extends Plugin
string $inbox, string $inbox,
array $to_actors, array $to_actors,
array &$retry_args, array &$retry_args,
): bool {
): EventResult {
try { try {
$data = Model::toType($activity); $data = Model::toType($activity);
if ($sender->isGroup()) { // When the sender is a group, if ($sender->isGroup()) { // When the sender is a group,
@@ -426,7 +427,7 @@ class ActivityPub extends Plugin
/** /**
* Add activity+json mimetype to WebFinger * Add activity+json mimetype to WebFinger
*/ */
public function onEndWebFingerProfileLinks(XML_XRD $xrd, Actor $object): bool
public function onEndWebFingerProfileLinks(XML_XRD $xrd, Actor $object): EventResult
{ {
if ($object->isPerson()) { if ($object->isPerson()) {
$link = new XML_XRD_Element_Link( $link = new XML_XRD_Element_Link(
@@ -442,7 +443,7 @@ class ActivityPub extends Plugin
/** /**
* When FreeNetwork component asks us to help with identifying Actors from XRDs * When FreeNetwork component asks us to help with identifying Actors from XRDs
*/ */
public function onFreeNetworkFoundXrd(XML_XRD $xrd, ?Actor &$actor = null): bool
public function onFreeNetworkFoundXrd(XML_XRD $xrd, ?Actor &$actor = null): EventResult
{ {
$addr = null; $addr = null;
foreach ($xrd->aliases as $alias) { foreach ($xrd->aliases as $alias) {
@@ -473,7 +474,7 @@ class ActivityPub extends Plugin
/** /**
* When FreeNetwork component asks us to help with identifying Actors from URIs * When FreeNetwork component asks us to help with identifying Actors from URIs
*/ */
public function onFreeNetworkFindMentions(string $target, ?Actor &$actor = null): bool
public function onFreeNetworkFindMentions(string $target, ?Actor &$actor = null): EventResult
{ {
try { try {
if (FreeNetworkActorProtocol::canIAddr('activitypub', $addr = Discovery::normalize($target))) { if (FreeNetworkActorProtocol::canIAddr('activitypub', $addr = Discovery::normalize($target))) {


+ 3
- 2
plugins/AttachmentCollections/AttachmentCollections.php View File

@@ -41,6 +41,7 @@ use App\Entity\Feed;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Collection\Util\MetaCollectionTrait; use Component\Collection\Util\MetaCollectionTrait;
use EventResult;
use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController; use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController;
use Plugin\AttachmentCollections\Entity\AttachmentCollection; use Plugin\AttachmentCollections\Entity\AttachmentCollection;
use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry; use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry;
@@ -122,7 +123,7 @@ class AttachmentCollections extends Plugin
return array_map(fn ($x) => $x['attachment_collection_id'], $res); return array_map(fn ($x) => $x['attachment_collection_id'], $res);
} }


public function onAddRoute(Router $r): bool
public function onAddRoute(Router $r): EventResult
{ {
// View all collections by actor id and nickname // View all collections by actor id and nickname
$r->connect( $r->connect(
@@ -149,7 +150,7 @@ class AttachmentCollections extends Plugin
return Event::next; return Event::next;
} }


public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
{ {
DB::persist(Feed::create([ DB::persist(Feed::create([
'actor_id' => $actor_id, 'actor_id' => $actor_id,


+ 3
- 2
plugins/AttachmentShowRelated/AttachmentShowRelated.php View File

@@ -28,11 +28,12 @@ use App\Core\Event;
use App\Core\Modules\Plugin; use App\Core\Modules\Plugin;
use App\Util\Common; use App\Util\Common;
use App\Util\Formatting; use App\Util\Formatting;
use EventResult;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class AttachmentShowRelated extends Plugin class AttachmentShowRelated extends Plugin
{ {
public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult
{ {
if ($vars['path'] === 'note_attachment_show') { if ($vars['path'] === 'note_attachment_show') {
$related_notes = DB::dql('select n from attachment_to_note an ' $related_notes = DB::dql('select n from attachment_to_note an '
@@ -54,7 +55,7 @@ class AttachmentShowRelated extends Plugin
* *
* @return bool hook value; true means continue processing, false means stop * @return bool hook value; true means continue processing, false means stop
*/ */
public function onEndShowStyles(array &$styles, string $path): bool
public function onEndShowStyles(array &$styles, string $path): EventResult
{ {
if ($path === 'note_attachment_show') { if ($path === 'note_attachment_show') {
$styles[] = '/assets/default_theme/pages/feeds.css'; $styles[] = '/assets/default_theme/pages/feeds.css';


+ 4
- 3
plugins/AudioEncoder/AudioEncoder.php View File

@@ -38,6 +38,7 @@ use function App\Core\I18n\_m;
use App\Core\Modules\Plugin; use App\Core\Modules\Plugin;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use App\Util\Formatting; use App\Util\Formatting;
use EventResult;
use FFMpeg\FFProbe as ffprobe; use FFMpeg\FFProbe as ffprobe;
use SplFileInfo; use SplFileInfo;


@@ -53,7 +54,7 @@ class AudioEncoder extends Plugin
return GSFile::mimetypeMajor($mimetype) === 'audio'; return GSFile::mimetypeMajor($mimetype) === 'audio';
} }


public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
public function onFileMetaAvailable(array &$event_map, string $mimetype): EventResult
{ {
if (!self::shouldHandle($mimetype)) { if (!self::shouldHandle($mimetype)) {
return Event::next; return Event::next;
@@ -90,7 +91,7 @@ class AudioEncoder extends Plugin
/** /**
* Generates the view for attachments of type Video * Generates the view for attachments of type Video
*/ */
public function onViewAttachment(array $vars, array &$res): bool
public function onViewAttachment(array $vars, array &$res): EventResult
{ {
if (!self::shouldHandle($vars['attachment']->getMimetype())) { if (!self::shouldHandle($vars['attachment']->getMimetype())) {
return Event::next; return Event::next;
@@ -110,7 +111,7 @@ class AudioEncoder extends Plugin
/** /**
* @throws ServerException * @throws ServerException
*/ */
public function onPluginVersion(array &$versions): bool
public function onPluginVersion(array &$versions): EventResult
{ {
$versions[] = [ $versions[] = [