EventHandler.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Comments;
  25. use OCA\Comments\Activity\Listener as ActivityListener;
  26. use OCA\Comments\Notification\Listener as NotificationListener;
  27. use OCP\Comments\CommentsEvent;
  28. use OCP\Comments\ICommentsEventHandler;
  29. /**
  30. * Class EventHandler
  31. *
  32. * @package OCA\Comments
  33. */
  34. class EventHandler implements ICommentsEventHandler {
  35. public function __construct(
  36. private ActivityListener $activityListener,
  37. private NotificationListener $notificationListener,
  38. ) {
  39. }
  40. public function handle(CommentsEvent $event): void {
  41. if ($event->getComment()->getObjectType() !== 'files') {
  42. // this is a 'files'-specific Handler
  43. return;
  44. }
  45. $eventType = $event->getEvent();
  46. if ($eventType === CommentsEvent::EVENT_ADD
  47. ) {
  48. $this->notificationHandler($event);
  49. $this->activityHandler($event);
  50. return;
  51. }
  52. $applicableEvents = [
  53. CommentsEvent::EVENT_PRE_UPDATE,
  54. CommentsEvent::EVENT_UPDATE,
  55. CommentsEvent::EVENT_DELETE,
  56. ];
  57. if (in_array($eventType, $applicableEvents)) {
  58. $this->notificationHandler($event);
  59. return;
  60. }
  61. }
  62. private function activityHandler(CommentsEvent $event): void {
  63. $this->activityListener->commentEvent($event);
  64. }
  65. private function notificationHandler(CommentsEvent $event): void {
  66. $this->notificationListener->evaluate($event);
  67. }
  68. }