aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/lib/Listener/CommentsEntityEventListener.php
blob: 5aeeb3c63ea6c6f894898ef878147140b9fabc57 (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
<?php

declare(strict_types=1);

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

use OCP\Comments\CommentsEntityEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\IRootFolder;

/** @template-implements IEventListener<CommentsEntityEvent> */
class CommentsEntityEventListener implements IEventListener {
	public function __construct(
		private IRootFolder $rootFolder,
		private ?string $userId = null,
	) {
	}

	public function handle(Event $event): void {
		if (!($event instanceof CommentsEntityEvent)) {
			// Unrelated
			return;
		}

		$event->addEntityCollection('files', function ($name): bool {
			$nodes = $this->rootFolder->getUserFolder($this->userId)->getById((int)$name);
			return !empty($nodes);
		});
	}
}