1
0

EventHandler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Comments;
  7. use OCA\Comments\Activity\Listener as ActivityListener;
  8. use OCA\Comments\Notification\Listener as NotificationListener;
  9. use OCP\Comments\CommentsEvent;
  10. use OCP\Comments\ICommentsEventHandler;
  11. /**
  12. * Class EventHandler
  13. *
  14. * @package OCA\Comments
  15. */
  16. class EventHandler implements ICommentsEventHandler {
  17. public function __construct(
  18. private ActivityListener $activityListener,
  19. private NotificationListener $notificationListener,
  20. ) {
  21. }
  22. public function handle(CommentsEvent $event): void {
  23. if ($event->getComment()->getObjectType() !== 'files') {
  24. // this is a 'files'-specific Handler
  25. return;
  26. }
  27. $eventType = $event->getEvent();
  28. if ($eventType === CommentsEvent::EVENT_ADD
  29. ) {
  30. $this->notificationHandler($event);
  31. $this->activityHandler($event);
  32. return;
  33. }
  34. $applicableEvents = [
  35. CommentsEvent::EVENT_PRE_UPDATE,
  36. CommentsEvent::EVENT_UPDATE,
  37. CommentsEvent::EVENT_DELETE,
  38. ];
  39. if (in_array($eventType, $applicableEvents)) {
  40. $this->notificationHandler($event);
  41. return;
  42. }
  43. }
  44. private function activityHandler(CommentsEvent $event): void {
  45. $this->activityListener->commentEvent($event);
  46. }
  47. private function notificationHandler(CommentsEvent $event): void {
  48. $this->notificationListener->evaluate($event);
  49. }
  50. }