diff options
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Service/TagService.php | 21 | ||||
-rw-r--r-- | apps/files/tests/Service/TagServiceTest.php | 6 | ||||
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/public/Files/Events/NodeAddedToFavorite.php | 66 | ||||
-rw-r--r-- | lib/public/Files/Events/NodeRemovedFromFavorite.php | 66 |
7 files changed, 152 insertions, 14 deletions
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 7021769752e..09db1be7570 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -57,6 +57,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\Collaboration\Resources\IProviderManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IL10N; use OCP\IPreview; @@ -110,7 +111,7 @@ class Application extends App implements IBootstrap { $c->get(IActivityManager::class), $c->get(ITagManager::class)->load(self::APP_ID), $server->getUserFolder(), - $server->getEventDispatcher() + $c->get(IEventDispatcher::class), ); }); diff --git a/apps/files/lib/Service/TagService.php b/apps/files/lib/Service/TagService.php index af4f7d0ef1e..e29848bf21d 100644 --- a/apps/files/lib/Service/TagService.php +++ b/apps/files/lib/Service/TagService.php @@ -26,12 +26,13 @@ namespace OCA\Files\Service; use OCA\Files\Activity\FavoriteProvider; use OCP\Activity\IManager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\NodeAddedToFavorite; +use OCP\Files\Events\NodeRemovedFromFavorite; use OCP\Files\Folder; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; /** * Service class to manage tags on files. @@ -46,7 +47,7 @@ class TagService { private $tagger; /** @var Folder|null */ private $homeFolder; - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $dispatcher; public function __construct( @@ -54,7 +55,7 @@ class TagService { IManager $activityManager, ?ITags $tagger, ?Folder $homeFolder, - EventDispatcherInterface $dispatcher + IEventDispatcher $dispatcher, ) { $this->userSession = $userSession; $this->activityManager = $activityManager; @@ -120,12 +121,12 @@ class TagService { return; } - $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; - $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ - 'userId' => $user->getUID(), - 'fileId' => $fileId, - 'path' => $path, - ])); + if ($addToFavorite) { + $event = new NodeAddedToFavorite($user, $fileId, $path); + } else { + $event = new NodeRemovedFromFavorite($user, $fileId, $path); + } + $this->dispatcher->dispatchTyped($event); $event = $this->activityManager->generateEvent(); try { diff --git a/apps/files/tests/Service/TagServiceTest.php b/apps/files/tests/Service/TagServiceTest.php index dce01e7170f..2b9bc5be460 100644 --- a/apps/files/tests/Service/TagServiceTest.php +++ b/apps/files/tests/Service/TagServiceTest.php @@ -29,10 +29,10 @@ namespace OCA\Files\Tests\Service; use OCA\Files\Service\TagService; use OCP\Activity\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class TagServiceTest @@ -59,7 +59,7 @@ class TagServiceTest extends \Test\TestCase { */ private $root; - /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $dispatcher; /** @@ -90,7 +90,7 @@ class TagServiceTest extends \Test\TestCase { ->willReturn($user); $this->root = \OC::$server->getUserFolder(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->tagger = \OC::$server->getTagManager()->load('files'); $this->tagService = $this->getTagService(['addActivity']); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 89ae83e83e4..38cad1e9eb4 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -309,7 +309,9 @@ return array( 'OCP\\Files\\Events\\FolderScannedEvent' => $baseDir . '/lib/public/Files/Events/FolderScannedEvent.php', 'OCP\\Files\\Events\\InvalidateMountCacheEvent' => $baseDir . '/lib/public/Files/Events/InvalidateMountCacheEvent.php', 'OCP\\Files\\Events\\NodeAddedToCache' => $baseDir . '/lib/public/Files/Events/NodeAddedToCache.php', + 'OCP\\Files\\Events\\NodeAddedToFavorite' => $baseDir . '/lib/public/Files/Events/NodeAddedToFavorite.php', 'OCP\\Files\\Events\\NodeRemovedFromCache' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromCache.php', + 'OCP\\Files\\Events\\NodeRemovedFromFavorite' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromFavorite.php', 'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodeEvent.php', 'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodesEvent.php', 'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 0480448a1b8..9083632b384 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -342,7 +342,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\Events\\FolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FolderScannedEvent.php', 'OCP\\Files\\Events\\InvalidateMountCacheEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/InvalidateMountCacheEvent.php', 'OCP\\Files\\Events\\NodeAddedToCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToCache.php', + 'OCP\\Files\\Events\\NodeAddedToFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToFavorite.php', 'OCP\\Files\\Events\\NodeRemovedFromCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromCache.php', + 'OCP\\Files\\Events\\NodeRemovedFromFavorite' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromFavorite.php', 'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodeEvent.php', 'OCP\\Files\\Events\\Node\\AbstractNodesEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodesEvent.php', 'OCP\\Files\\Events\\Node\\BeforeNodeCopiedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeCopiedEvent.php', diff --git a/lib/public/Files/Events/NodeAddedToFavorite.php b/lib/public/Files/Events/NodeAddedToFavorite.php new file mode 100644 index 00000000000..d3f84582e46 --- /dev/null +++ b/lib/public/Files/Events/NodeAddedToFavorite.php @@ -0,0 +1,66 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCP\Files\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 28.0.0 + */ +class NodeAddedToFavorite extends Event { + /** + * @since 28.0.0 + */ + public function __construct( + protected IUser $user, + protected int $fileId, + protected string $path, + ) { + parent::__construct(); + } + + /** + * @since 28.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @since 28.0.0 + */ + public function getFileId(): int { + return $this->fileId; + } + + /** + * @since 28.0.0 + */ + public function getPath(): string { + return $this->path; + } +} diff --git a/lib/public/Files/Events/NodeRemovedFromFavorite.php b/lib/public/Files/Events/NodeRemovedFromFavorite.php new file mode 100644 index 00000000000..72b43558bec --- /dev/null +++ b/lib/public/Files/Events/NodeRemovedFromFavorite.php @@ -0,0 +1,66 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCP\Files\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 28.0.0 + */ +class NodeRemovedFromFavorite extends Event { + /** + * @since 28.0.0 + */ + public function __construct( + protected IUser $user, + protected int $fileId, + protected string $path, + ) { + parent::__construct(); + } + + /** + * @since 28.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @since 28.0.0 + */ + public function getFileId(): int { + return $this->fileId; + } + + /** + * @since 28.0.0 + */ + public function getPath(): string { + return $this->path; + } +} |