aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2024-06-18 14:11:32 +0200
committerJulius Härtl <jus@bitgrid.net>2024-06-26 18:13:07 +0200
commit9713dd3fa990c5dabfa07b1049ac1a8a0f1edb27 (patch)
treea03f5b678a4670c8d49f62e852c1e3a4c3a36bfe /apps/comments/lib
parent9b05759c03f304a518b37cabfcc2fd7cc4fa4fef (diff)
downloadnextcloud-server-9713dd3fa990c5dabfa07b1049ac1a8a0f1edb27.tar.gz
nextcloud-server-9713dd3fa990c5dabfa07b1049ac1a8a0f1edb27.zip
chore: Move comments event handler to use proper event dispatcher
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r--apps/comments/lib/AppInfo/Application.php19
-rw-r--r--apps/comments/lib/Listener/CommentsEventListener.php (renamed from apps/comments/lib/EventHandler.php)24
2 files changed, 22 insertions, 21 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index 8951387b362..15b576938d2 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -5,10 +5,9 @@
*/
namespace OCA\Comments\AppInfo;
-use Closure;
use OCA\Comments\Capabilities;
-use OCA\Comments\EventHandler;
use OCA\Comments\Listener\CommentsEntityEventListener;
+use OCA\Comments\Listener\CommentsEventListener;
use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\MaxAutoCompleteResultsInitialState;
@@ -22,9 +21,8 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
-use OCP\Comments\ICommentsManager;
+use OCP\Comments\CommentsEvent;
use OCP\ISearch;
-use OCP\IServerContainer;
class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
@@ -48,6 +46,11 @@ class Application extends App implements IBootstrap {
CommentsEntityEvent::class,
CommentsEntityEventListener::class
);
+ $context->registerEventListener(
+ CommentsEvent::class,
+ CommentsEventListener::class,
+ );
+
$context->registerSearchProvider(CommentsSearchProvider::class);
$context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
@@ -56,14 +59,6 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
- $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
-
$context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
}
-
- protected function registerCommentsEventHandler(IServerContainer $container): void {
- $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
- return $this->getContainer()->get(EventHandler::class);
- });
- }
}
diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/Listener/CommentsEventListener.php
index 3ad76941444..a1e44995162 100644
--- a/apps/comments/lib/EventHandler.php
+++ b/apps/comments/lib/Listener/CommentsEventListener.php
@@ -1,28 +1,34 @@
<?php
+
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Comments;
+
+
+namespace OCA\Comments\Listener;
use OCA\Comments\Activity\Listener as ActivityListener;
use OCA\Comments\Notification\Listener as NotificationListener;
use OCP\Comments\CommentsEvent;
-use OCP\Comments\ICommentsEventHandler;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
-/**
- * Class EventHandler
- *
- * @package OCA\Comments
- */
-class EventHandler implements ICommentsEventHandler {
+/** @template-implements IEventListener<CommentsEvent|Event> */
+class CommentsEventListener implements IEventListener {
public function __construct(
private ActivityListener $activityListener,
private NotificationListener $notificationListener,
) {
}
- public function handle(CommentsEvent $event): void {
+ public function handle(Event $event): void {
+ if (!$event instanceof CommentsEvent) {
+ return;
+ }
+
if ($event->getComment()->getObjectType() !== 'files') {
// this is a 'files'-specific Handler
return;