aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Listener/CalendarPublicationListener.php
blob: 94a0a208d4e84f839b9432c125eb598541ea5f66 (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
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\DAV\Listener;

use OCA\DAV\CalDAV\Activity\Backend;
use OCA\DAV\Events\CalendarPublishedEvent;
use OCA\DAV\Events\CalendarUnpublishedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<CalendarPublishedEvent|CalendarUnpublishedEvent> */
class CalendarPublicationListener implements IEventListener {
	public function __construct(
		private Backend $activityBackend,
		private LoggerInterface $logger,
	) {
	}

	/**
	 * In case the user has set their default calendar to the deleted one
	 */
	public function handle(Event $event): void {
		if ($event instanceof CalendarPublishedEvent) {
			$this->logger->debug('Creating activity for Calendar being published');

			$this->activityBackend->onCalendarPublication(
				$event->getCalendarData(),
				true
			);
		} elseif ($event instanceof CalendarUnpublishedEvent) {
			$this->logger->debug('Creating activity for Calendar being unpublished');

			$this->activityBackend->onCalendarPublication(
				$event->getCalendarData(),
				false
			);
		}
	}
}