diff options
author | grnd-alt <salimbelakkaf@outlook.de> | 2024-10-24 16:10:54 +0200 |
---|---|---|
committer | grnd-alt <salimbelakkaf@outlook.de> | 2024-12-03 20:56:36 +0100 |
commit | 2d02d835978a82bcff4845adc702d8033b4fcb60 (patch) | |
tree | 0d38d53f005ad1aeba735115b7f56e9fb7081cf3 /apps/files/lib/Listener | |
parent | 5ee4c9effa991306d2bb536c3ce23d1fe3eaccc3 (diff) | |
download | nextcloud-server-2d02d835978a82bcff4845adc702d8033b4fcb60.tar.gz nextcloud-server-2d02d835978a82bcff4845adc702d8033b4fcb60.zip |
fix(dav): add activity logging for favorites in dav
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
Diffstat (limited to 'apps/files/lib/Listener')
-rw-r--r-- | apps/files/lib/Listener/NodeAddedToFavoriteListener.php | 43 | ||||
-rw-r--r-- | apps/files/lib/Listener/NodeRemovedFromFavoriteListener.php | 43 |
2 files changed, 86 insertions, 0 deletions
diff --git a/apps/files/lib/Listener/NodeAddedToFavoriteListener.php b/apps/files/lib/Listener/NodeAddedToFavoriteListener.php new file mode 100644 index 00000000000..827c1851d3d --- /dev/null +++ b/apps/files/lib/Listener/NodeAddedToFavoriteListener.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\Files\Listener; + +use OCA\Files\Activity\FavoriteProvider; +use OCP\Activity\IManager as IActivityManager; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Files\Events\NodeAddedToFavorite; + +/** @template-implements IEventListener<NodeAddedToFavorite> */ +class NodeAddedToFavoriteListener implements IEventListener { + public function __construct( + private IActivityManager $activityManager, + ) { + } + public function handle(Event $event):void { + if (!($event instanceof NodeAddedToFavorite)) { + return; + } + $activityEvent = $this->activityManager->generateEvent(); + try { + $activityEvent->setApp('files') + ->setObject('files', $event->getFileId(), $event->getPath()) + ->setType('favorite') + ->setAuthor($event->getUser()->getUID()) + ->setAffectedUser($event->getUser()->getUID()) + ->setTimestamp(time()) + ->setSubject( + FavoriteProvider::SUBJECT_ADDED, + ['id' => $event->getFileId(), 'path' => $event->getPath()] + ); + $this->activityManager->publish($activityEvent); + } catch (\InvalidArgumentException $e) { + } catch (\BadMethodCallException $e) { + } + } +} diff --git a/apps/files/lib/Listener/NodeRemovedFromFavoriteListener.php b/apps/files/lib/Listener/NodeRemovedFromFavoriteListener.php new file mode 100644 index 00000000000..fe39d4af540 --- /dev/null +++ b/apps/files/lib/Listener/NodeRemovedFromFavoriteListener.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\Files\Listener; + +use OCA\Files\Activity\FavoriteProvider; +use OCP\Activity\IManager as IActivityManager; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Files\Events\NodeRemovedFromFavorite; + +/** @template-implements IEventListener<NodeRemovedFromFavorite> */ +class NodeRemovedFromFavoriteListener implements IEventListener { + public function __construct( + private IActivityManager $activityManager, + ) { + } + public function handle(Event $event):void { + if (!($event instanceof NodeRemovedFromFavorite)) { + return; + } + $activityEvent = $this->activityManager->generateEvent(); + try { + $activityEvent->setApp('files') + ->setObject('files', $event->getFileId(), $event->getPath()) + ->setType('favorite') + ->setAuthor($event->getUser()->getUID()) + ->setAffectedUser($event->getUser()->getUID()) + ->setTimestamp(time()) + ->setSubject( + FavoriteProvider::SUBJECT_REMOVED, + ['id' => $event->getFileId(), 'path' => $event->getPath()] + ); + $this->activityManager->publish($activityEvent); + } catch (\InvalidArgumentException $e) { + } catch (\BadMethodCallException $e) { + } + } +} |