From 3af6d112ce9253e0bbb6e545c767253bd251d9a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Jan 2018 11:20:21 +0100 Subject: Add events for favorites Signed-off-by: Joas Schilling --- apps/files/lib/AppInfo/Application.php | 5 +++-- apps/files/lib/Service/TagService.php | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'apps/files/lib') diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 7042af10ca2..e55d1c549a5 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -81,13 +81,14 @@ class Application extends App { $container->registerService('Tagger', function(IContainer $c) { return $c->query('ServerContainer')->getTagManager()->load('files'); }); - $container->registerService('TagService', function(IContainer $c) { + $container->registerService('TagService', function(IContainer $c) use ($server) { $homeFolder = $c->query('ServerContainer')->getUserFolder(); return new TagService( $c->query('ServerContainer')->getUserSession(), $c->query('ServerContainer')->getActivityManager(), $c->query('Tagger'), - $homeFolder + $homeFolder, + $server->getEventDispatcher() ); }); diff --git a/apps/files/lib/Service/TagService.php b/apps/files/lib/Service/TagService.php index d812b16c30e..7437f0c31ad 100644 --- a/apps/files/lib/Service/TagService.php +++ b/apps/files/lib/Service/TagService.php @@ -31,6 +31,8 @@ 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. @@ -45,23 +47,28 @@ class TagService { private $tagger; /** @var Folder */ private $homeFolder; + /** @var EventDispatcherInterface */ + private $dispatcher; /** * @param IUserSession $userSession * @param IManager $activityManager * @param ITags $tagger * @param Folder $homeFolder + * @param EventDispatcherInterface $dispatcher */ public function __construct( IUserSession $userSession, IManager $activityManager, ITags $tagger, - Folder $homeFolder + Folder $homeFolder, + EventDispatcherInterface $dispatcher ) { $this->userSession = $userSession; $this->activityManager = $activityManager; $this->tagger = $tagger; $this->homeFolder = $homeFolder; + $this->dispatcher = $dispatcher; } /** @@ -114,6 +121,13 @@ class TagService { return; } + $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; + $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ + 'userId' => $user->getUID(), + 'fileId' => $fileId, + 'path' => $path, + ])); + $event = $this->activityManager->generateEvent(); try { $event->setApp('files') -- cgit v1.2.3