aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments/lib')
-rw-r--r--apps/comments/lib/Activity/Filter.php22
-rw-r--r--apps/comments/lib/Activity/Listener.php31
-rw-r--r--apps/comments/lib/Activity/Provider.php52
-rw-r--r--apps/comments/lib/Activity/Setting.php34
-rw-r--r--apps/comments/lib/AppInfo/Application.php48
-rw-r--r--apps/comments/lib/Capabilities.php21
-rw-r--r--apps/comments/lib/Collaboration/CommentersSorter.php23
-rw-r--r--apps/comments/lib/Controller/NotificationsController.php33
-rw-r--r--apps/comments/lib/EventHandler.php75
-rw-r--r--apps/comments/lib/Listener/CommentsEntityEventListener.php22
-rw-r--r--apps/comments/lib/Listener/CommentsEventListener.php63
-rw-r--r--apps/comments/lib/Listener/LoadAdditionalScripts.php24
-rw-r--r--apps/comments/lib/Listener/LoadSidebarScripts.php23
-rw-r--r--apps/comments/lib/MaxAutoCompleteResultsInitialState.php23
-rw-r--r--apps/comments/lib/Notification/Listener.php26
-rw-r--r--apps/comments/lib/Notification/Notifier.php40
-rw-r--r--apps/comments/lib/Search/CommentsSearchProvider.php23
-rw-r--r--apps/comments/lib/Search/LegacyProvider.php29
-rw-r--r--apps/comments/lib/Search/Result.php34
19 files changed, 172 insertions, 474 deletions
diff --git a/apps/comments/lib/Activity/Filter.php b/apps/comments/lib/Activity/Filter.php
index c46da1a162f..8dcafd872d7 100644
--- a/apps/comments/lib/Activity/Filter.php
+++ b/apps/comments/lib/Activity/Filter.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Activity;
diff --git a/apps/comments/lib/Activity/Listener.php b/apps/comments/lib/Activity/Listener.php
index 341b2e7ac65..45064f4a6be 100644
--- a/apps/comments/lib/Activity/Listener.php
+++ b/apps/comments/lib/Activity/Listener.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Comments\Activity;
@@ -48,7 +31,7 @@ class Listener {
public function commentEvent(CommentsEvent $event): void {
if ($event->getComment()->getObjectType() !== 'files'
|| $event->getEvent() !== CommentsEvent::EVENT_ADD
- || !$this->appManager->isInstalled('activity')) {
+ || !$this->appManager->isEnabledForAnyone('activity')) {
// Comment not for file, not adding a comment or no activity-app enabled (save the energy)
return;
}
@@ -84,7 +67,7 @@ class Listener {
$activity->setApp('comments')
->setType('comments')
->setAuthor($actor)
- ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId())
+ ->setObject($event->getComment()->getObjectType(), (int)$event->getComment()->getObjectId())
->setMessage('add_comment_message', [
'commentId' => $event->getComment()->getId(),
]);
@@ -96,7 +79,7 @@ class Listener {
$activity->setSubject('add_comment_subject', [
'actor' => $actor,
- 'fileId' => (int) $event->getComment()->getObjectId(),
+ 'fileId' => (int)$event->getComment()->getObjectId(),
'filePath' => trim($path, '/'),
]);
$this->activityManager->publish($activity);
diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php
index b139b18371d..ee53357efdb 100644
--- a/apps/comments/lib/Activity/Provider.php
+++ b/apps/comments/lib/Activity/Provider.php
@@ -1,29 +1,12 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Activity;
+use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
@@ -51,12 +34,12 @@ class Provider implements IProvider {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
* @since 11.0.0
*/
- public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent {
+ public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'comments') {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
$this->l = $this->languageFactory->get('comments', $language);
@@ -72,19 +55,19 @@ class Provider implements IProvider {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
- } catch (\InvalidArgumentException $e) {
+ } catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
return $this->parseLongVersion($event);
- } else {
- throw new \InvalidArgumentException();
}
+ throw new UnknownActivityException();
+
}
/**
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
*/
protected function parseShortVersion(IEvent $event): IEvent {
$subjectParameters = $this->getSubjectParameters($event);
@@ -99,14 +82,14 @@ class Provider implements IProvider {
]);
}
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
return $event;
}
/**
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
*/
protected function parseLongVersion(IEvent $event): IEvent {
$subjectParameters = $this->getSubjectParameters($event);
@@ -131,7 +114,7 @@ class Provider implements IProvider {
]);
}
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
return $event;
@@ -167,7 +150,7 @@ class Provider implements IProvider {
$commentId = $messageParameters['commentId'] ?? $messageParameters[0];
try {
- $comment = $this->commentsManager->get((string) $commentId);
+ $comment = $this->commentsManager->get((string)$commentId);
$message = $comment->getMessage();
$mentionCount = 1;
@@ -192,10 +175,13 @@ class Provider implements IProvider {
}
}
+ /**
+ * @return array<string, string>
+ */
protected function generateFileParameter(int $id, string $path): array {
return [
'type' => 'file',
- 'id' => $id,
+ 'id' => (string)$id,
'name' => basename($path),
'path' => $path,
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
diff --git a/apps/comments/lib/Activity/Setting.php b/apps/comments/lib/Activity/Setting.php
index 4413388b53b..7fbf4001b20 100644
--- a/apps/comments/lib/Activity/Setting.php
+++ b/apps/comments/lib/Activity/Setting.php
@@ -1,31 +1,15 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Activity;
-use OCP\Activity\ISetting;
+use OCP\Activity\ActivitySettings;
use OCP\IL10N;
-class Setting implements ISetting {
+class Setting extends ActivitySettings {
public function __construct(
protected IL10N $l,
) {
@@ -39,6 +23,14 @@ class Setting implements ISetting {
return $this->l->t('<strong>Comments</strong> for files');
}
+ public function getGroupIdentifier() {
+ return 'files';
+ }
+
+ public function getGroupName() {
+ return $this->l->t('Files');
+ }
+
public function getPriority(): int {
return 50;
}
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index a6d6d9fb78d..db4a2ce614c 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -1,41 +1,19 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\AppInfo;
-use Closure;
use OCA\Comments\Capabilities;
-use OCA\Comments\EventHandler;
use OCA\Comments\Listener\CommentsEntityEventListener;
+use OCA\Comments\Listener\CommentsEventListener;
use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\MaxAutoCompleteResultsInitialState;
use OCA\Comments\Notification\Notifier;
use OCA\Comments\Search\CommentsSearchProvider;
-use OCA\Comments\Search\LegacyProvider;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCP\AppFramework\App;
@@ -43,9 +21,7 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
-use OCP\Comments\ICommentsManager;
-use OCP\ISearch;
-use OCP\IServerContainer;
+use OCP\Comments\CommentsEvent;
class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
@@ -69,6 +45,11 @@ class Application extends App implements IBootstrap {
CommentsEntityEvent::class,
CommentsEntityEventListener::class
);
+ $context->registerEventListener(
+ CommentsEvent::class,
+ CommentsEventListener::class,
+ );
+
$context->registerSearchProvider(CommentsSearchProvider::class);
$context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
@@ -77,14 +58,5 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
- $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
-
- $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
- }
-
- protected function registerCommentsEventHandler(IServerContainer $container): void {
- $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
- return $this->getContainer()->get(EventHandler::class);
- });
}
}
diff --git a/apps/comments/lib/Capabilities.php b/apps/comments/lib/Capabilities.php
index 597f248412c..2057803d867 100644
--- a/apps/comments/lib/Capabilities.php
+++ b/apps/comments/lib/Capabilities.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments;
diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php
index b30c91ea2e8..baa27155573 100644
--- a/apps/comments/lib/Collaboration/CommentersSorter.php
+++ b/apps/comments/lib/Collaboration/CommentersSorter.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Collaboration;
diff --git a/apps/comments/lib/Controller/NotificationsController.php b/apps/comments/lib/Controller/NotificationsController.php
index 1e1f0e563e2..0937b6929b8 100644
--- a/apps/comments/lib/Controller/NotificationsController.php
+++ b/apps/comments/lib/Controller/NotificationsController.php
@@ -1,32 +1,16 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
+use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\Comments\IComment;
@@ -50,15 +34,12 @@ class NotificationsController extends Controller {
protected IRootFolder $rootFolder,
protected IURLGenerator $urlGenerator,
protected IManager $notificationManager,
- protected IUserSession $userSession
+ protected IUserSession $userSession,
) {
parent::__construct($appName, $request);
}
/**
- * @PublicPage
- * @NoCSRFRequired
- *
* View a notification
*
* @param string $id ID of the notification
@@ -68,6 +49,8 @@ class NotificationsController extends Controller {
* 303: Redirected to notification
* 404: Notification not found
*/
+ #[PublicPage]
+ #[NoCSRFRequired]
public function view(string $id): RedirectResponse|NotFoundResponse {
$currentUser = $this->userSession->getUser();
if (!$currentUser instanceof IUser) {
diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/EventHandler.php
deleted file mode 100644
index b3a6e5b754b..00000000000
--- a/apps/comments/lib/EventHandler.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-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);
- }
-}
diff --git a/apps/comments/lib/Listener/CommentsEntityEventListener.php b/apps/comments/lib/Listener/CommentsEntityEventListener.php
index 38604345f2f..5aeeb3c63ea 100644
--- a/apps/comments/lib/Listener/CommentsEntityEventListener.php
+++ b/apps/comments/lib/Listener/CommentsEntityEventListener.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Listener;
@@ -30,6 +13,7 @@ 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,
diff --git a/apps/comments/lib/Listener/CommentsEventListener.php b/apps/comments/lib/Listener/CommentsEventListener.php
new file mode 100644
index 00000000000..a1e44995162
--- /dev/null
+++ b/apps/comments/lib/Listener/CommentsEventListener.php
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+
+namespace OCA\Comments\Listener;
+
+use OCA\Comments\Activity\Listener as ActivityListener;
+use OCA\Comments\Notification\Listener as NotificationListener;
+use OCP\Comments\CommentsEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/** @template-implements IEventListener<CommentsEvent|Event> */
+class CommentsEventListener implements IEventListener {
+ public function __construct(
+ private ActivityListener $activityListener,
+ private NotificationListener $notificationListener,
+ ) {
+ }
+
+ public function handle(Event $event): void {
+ if (!$event instanceof CommentsEvent) {
+ return;
+ }
+
+ 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);
+ }
+}
diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php
index e37b28cfae5..81e1bfe5310 100644
--- a/apps/comments/lib/Listener/LoadAdditionalScripts.php
+++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Listener;
@@ -33,6 +14,7 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
+/** @template-implements IEventListener<LoadAdditionalScriptsEvent> */
class LoadAdditionalScripts implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof LoadAdditionalScriptsEvent)) {
diff --git a/apps/comments/lib/Listener/LoadSidebarScripts.php b/apps/comments/lib/Listener/LoadSidebarScripts.php
index db1f2dc86f7..906fe40fed2 100644
--- a/apps/comments/lib/Listener/LoadSidebarScripts.php
+++ b/apps/comments/lib/Listener/LoadSidebarScripts.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Listener;
@@ -35,6 +17,7 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
+/** @template-implements IEventListener<LoadSidebar> */
class LoadSidebarScripts implements IEventListener {
public function __construct(
private ICommentsManager $commentsManager,
diff --git a/apps/comments/lib/MaxAutoCompleteResultsInitialState.php b/apps/comments/lib/MaxAutoCompleteResultsInitialState.php
index ed0db5927cf..b4c8f8719db 100644
--- a/apps/comments/lib/MaxAutoCompleteResultsInitialState.php
+++ b/apps/comments/lib/MaxAutoCompleteResultsInitialState.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments;
diff --git a/apps/comments/lib/Notification/Listener.php b/apps/comments/lib/Notification/Listener.php
index c3d409f8d06..43922f85e59 100644
--- a/apps/comments/lib/Notification/Listener.php
+++ b/apps/comments/lib/Notification/Listener.php
@@ -1,25 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Comments\Notification;
@@ -32,7 +16,7 @@ use OCP\Notification\INotification;
class Listener {
public function __construct(
protected IManager $notificationManager,
- protected IUserManager $userManager
+ protected IUserManager $userManager,
) {
}
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php
index 94a46bbce78..62562bf42aa 100644
--- a/apps/comments/lib/Notification/Notifier.php
+++ b/apps/comments/lib/Notification/Notifier.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Comments\Notification;
@@ -34,6 +17,7 @@ use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
+use OCP\Notification\UnknownNotificationException;
class Notifier implements INotifier {
public function __construct(
@@ -41,7 +25,7 @@ class Notifier implements INotifier {
protected IRootFolder $rootFolder,
protected ICommentsManager $commentsManager,
protected IURLGenerator $url,
- protected IUserManager $userManager
+ protected IUserManager $userManager,
) {
}
@@ -69,19 +53,19 @@ class Notifier implements INotifier {
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
- * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws UnknownNotificationException When the notification was not prepared by a notifier
* @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'comments') {
- throw new \InvalidArgumentException();
+ throw new UnknownNotificationException();
}
try {
$comment = $this->commentsManager->get($notification->getObjectId());
} catch (NotFoundException $e) {
// needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all
- throw new \InvalidArgumentException('Comment not found', 0, $e);
+ throw new UnknownNotificationException('Comment not found', 0, $e);
}
$l = $this->l10nFactory->get('comments', $languageCode);
$displayName = $comment->getActorId();
@@ -97,7 +81,7 @@ class Notifier implements INotifier {
case 'mention':
$parameters = $notification->getSubjectParameters();
if ($parameters[0] !== 'files') {
- throw new \InvalidArgumentException('Unsupported comment object');
+ throw new UnknownNotificationException('Unsupported comment object');
}
$userFolder = $this->rootFolder->getUserFolder($notification->getUser());
$nodes = $userFolder->getById((int)$parameters[1]);
@@ -123,7 +107,7 @@ class Notifier implements INotifier {
];
if ($isDeletedActor) {
- $subject = $l->t('You were mentioned on "{file}", in a comment by a user that has since been deleted');
+ $subject = $l->t('You were mentioned on "{file}", in a comment by an account that has since been deleted');
} else {
$subject = $l->t('{user} mentioned you in a comment on "{file}"');
$subjectParameters['user'] = [
@@ -145,7 +129,7 @@ class Notifier implements INotifier {
break;
default:
- throw new \InvalidArgumentException('Invalid subject');
+ throw new UnknownNotificationException('Invalid subject');
}
}
diff --git a/apps/comments/lib/Search/CommentsSearchProvider.php b/apps/comments/lib/Search/CommentsSearchProvider.php
index 7d7e255d278..87a658cab1c 100644
--- a/apps/comments/lib/Search/CommentsSearchProvider.php
+++ b/apps/comments/lib/Search/CommentsSearchProvider.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Search;
diff --git a/apps/comments/lib/Search/LegacyProvider.php b/apps/comments/lib/Search/LegacyProvider.php
index 55f7ef8eeb9..a269c418d06 100644
--- a/apps/comments/lib/Search/LegacyProvider.php
+++ b/apps/comments/lib/Search/LegacyProvider.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Search;
@@ -31,7 +14,9 @@ use OCP\Files\Folder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser;
+use OCP\IUserSession;
use OCP\Search\Provider;
+use OCP\Server;
use function count;
class LegacyProvider extends Provider {
@@ -43,8 +28,8 @@ class LegacyProvider extends Provider {
* @since 7.0.0
*/
public function search($query): array {
- $cm = \OC::$server->get(ICommentsManager::class);
- $us = \OC::$server->getUserSession();
+ $cm = Server::get(ICommentsManager::class);
+ $us = Server::get(IUserSession::class);
$user = $us->getUser();
if (!$user instanceof IUser) {
@@ -102,7 +87,7 @@ class LegacyProvider extends Provider {
* @throws NotFoundException
*/
protected function getFileForComment(Folder $userFolder, IComment $comment): Node {
- $nodes = $userFolder->getById((int) $comment->getObjectId());
+ $nodes = $userFolder->getById((int)$comment->getObjectId());
if (empty($nodes)) {
throw new NotFoundException('File not found');
}
diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php
index f4abf3864c1..7478c110d63 100644
--- a/apps/comments/lib/Search/Result.php
+++ b/apps/comments/lib/Search/Result.php
@@ -1,26 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Michał Węgrzynek <michal.wegrzynek@malloc.com.pl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Search;
@@ -47,10 +29,6 @@ class Result extends BaseResult {
/**
* @deprecated 20.0.0
*/
- public string $authorName;
- /**
- * @deprecated 20.0.0
- */
public $path;
/**
* @deprecated 20.0.0
@@ -64,7 +42,10 @@ class Result extends BaseResult {
public function __construct(
string $search,
IComment $comment,
- string $authorName,
+ /**
+ * @deprecated 20.0.0
+ */
+ public string $authorName,
string $path,
) {
parent::__construct(
@@ -75,7 +56,6 @@ class Result extends BaseResult {
$this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search);
$this->authorId = $comment->getActorId();
- $this->authorName = $authorName;
$this->fileName = basename($path);
$this->path = $this->getVisiblePath($path);
}