blob: 3ad76941444c2cd1ac592a4f731ab4d62f4aaae6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 {
public function __construct(
private ActivityListener $activityListener,
private NotificationListener $notificationListener,
) {
}
public function handle(CommentsEvent $event): void {
if ($event->getComment()->getObjectType() !== 'files') {
// this is a 'files'-specific Handler
return;
}
$eventType = $event->getEvent();
if ($eventType === CommentsEvent::EVENT_ADD
) {
$this->notificationHandler($event);
$this->activityHandler($event);
return;
}
$applicableEvents = [
CommentsEvent::EVENT_PRE_UPDATE,
CommentsEvent::EVENT_UPDATE,
CommentsEvent::EVENT_DELETE,
];
if (in_array($eventType, $applicableEvents)) {
$this->notificationHandler($event);
return;
}
}
private function activityHandler(CommentsEvent $event): void {
$this->activityListener->commentEvent($event);
}
private function notificationHandler(CommentsEvent $event): void {
$this->notificationListener->evaluate($event);
}
}
|