2016-05-09 04:02:07 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-05-09 04:02:07 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Comments;
|
|
|
|
|
|
|
|
|
|
use OCA\Comments\Activity\Listener as ActivityListener;
|
|
|
|
|
use OCA\Comments\Notification\Listener as NotificationListener;
|
|
|
|
|
use OCP\Comments\CommentsEvent;
|
|
|
|
|
use OCP\Comments\ICommentsEventHandler;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class EventHandler
|
|
|
|
|
*
|
|
|
|
|
* @package OCA\Comments
|
|
|
|
|
*/
|
|
|
|
|
class EventHandler implements ICommentsEventHandler {
|
2023-07-07 14:54:48 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private ActivityListener $activityListener,
|
|
|
|
|
private NotificationListener $notificationListener,
|
|
|
|
|
) {
|
2016-05-09 04:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-25 05:19:47 -05:00
|
|
|
public function handle(CommentsEvent $event): void {
|
2020-04-10 08:19:56 -04:00
|
|
|
if ($event->getComment()->getObjectType() !== 'files') {
|
2016-05-09 04:02:07 -04:00
|
|
|
// this is a 'files'-specific Handler
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 19:10:49 -04:00
|
|
|
$eventType = $event->getEvent();
|
2020-04-10 08:19:56 -04:00
|
|
|
if ($eventType === CommentsEvent::EVENT_ADD
|
2016-05-09 04:02:07 -04:00
|
|
|
) {
|
2016-10-12 12:06:22 -04:00
|
|
|
$this->notificationHandler($event);
|
|
|
|
|
$this->activityHandler($event);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 09:36:05 -04:00
|
|
|
$applicableEvents = [
|
|
|
|
|
CommentsEvent::EVENT_PRE_UPDATE,
|
|
|
|
|
CommentsEvent::EVENT_UPDATE,
|
|
|
|
|
CommentsEvent::EVENT_DELETE,
|
|
|
|
|
];
|
2020-04-10 08:19:56 -04:00
|
|
|
if (in_array($eventType, $applicableEvents)) {
|
2016-10-12 12:06:22 -04:00
|
|
|
$this->notificationHandler($event);
|
2016-10-07 19:10:49 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2016-05-09 04:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-25 05:19:47 -05:00
|
|
|
private function activityHandler(CommentsEvent $event): void {
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->activityListener->commentEvent($event);
|
2016-05-09 04:02:07 -04:00
|
|
|
}
|
2016-10-07 19:10:49 -04:00
|
|
|
|
2022-11-25 05:19:47 -05:00
|
|
|
private function notificationHandler(CommentsEvent $event): void {
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->notificationListener->evaluate($event);
|
2016-10-07 19:10:49 -04:00
|
|
|
}
|
2016-05-09 04:02:07 -04:00
|
|
|
}
|