diff options
Diffstat (limited to 'apps/comments/lib')
-rw-r--r-- | apps/comments/lib/Activity/Filter.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Activity/Listener.php | 6 | ||||
-rw-r--r-- | apps/comments/lib/Activity/Provider.php | 27 | ||||
-rw-r--r-- | apps/comments/lib/Activity/Setting.php | 13 | ||||
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 4 | ||||
-rw-r--r-- | apps/comments/lib/Collaboration/CommentersSorter.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Controller/NotificationsController.php | 10 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Listener.php | 2 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 2 | ||||
-rw-r--r-- | apps/comments/lib/Search/LegacyProvider.php | 8 | ||||
-rw-r--r-- | apps/comments/lib/Search/Result.php | 11 |
11 files changed, 51 insertions, 34 deletions
diff --git a/apps/comments/lib/Activity/Filter.php b/apps/comments/lib/Activity/Filter.php index 6f010d855cb..8dcafd872d7 100644 --- a/apps/comments/lib/Activity/Filter.php +++ b/apps/comments/lib/Activity/Filter.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/apps/comments/lib/Activity/Listener.php b/apps/comments/lib/Activity/Listener.php index f49f2077a61..45064f4a6be 100644 --- a/apps/comments/lib/Activity/Listener.php +++ b/apps/comments/lib/Activity/Listener.php @@ -31,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; } @@ -67,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(), ]); @@ -79,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 704ef0e0a48..ee53357efdb 100644 --- a/apps/comments/lib/Activity/Provider.php +++ b/apps/comments/lib/Activity/Provider.php @@ -1,10 +1,12 @@ <?php + /** * 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; @@ -32,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 { if ($event->getApp() !== 'comments') { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } $this->l = $this->languageFactory->get('comments', $language); @@ -53,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); @@ -80,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); @@ -112,7 +114,7 @@ class Provider implements IProvider { ]); } } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } return $event; @@ -148,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; @@ -173,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 cc7c47784ac..7fbf4001b20 100644 --- a/apps/comments/lib/Activity/Setting.php +++ b/apps/comments/lib/Activity/Setting.php @@ -1,14 +1,15 @@ <?php + /** * 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, ) { @@ -22,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 15b576938d2..db4a2ce614c 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -13,7 +14,6 @@ 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; @@ -22,7 +22,6 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Comments\CommentsEntityEvent; use OCP\Comments\CommentsEvent; -use OCP\ISearch; class Application extends App implements IBootstrap { public const APP_ID = 'comments'; @@ -59,6 +58,5 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]); } } diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php index 46fec87c777..baa27155573 100644 --- a/apps/comments/lib/Collaboration/CommentersSorter.php +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/apps/comments/lib/Controller/NotificationsController.php b/apps/comments/lib/Controller/NotificationsController.php index 408efc46973..0937b6929b8 100644 --- a/apps/comments/lib/Controller/NotificationsController.php +++ b/apps/comments/lib/Controller/NotificationsController.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,7 +8,9 @@ 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; @@ -31,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 @@ -49,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/Notification/Listener.php b/apps/comments/lib/Notification/Listener.php index 44fb8fe3f4c..43922f85e59 100644 --- a/apps/comments/lib/Notification/Listener.php +++ b/apps/comments/lib/Notification/Listener.php @@ -16,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 d5563ef7d85..62562bf42aa 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -25,7 +25,7 @@ class Notifier implements INotifier { protected IRootFolder $rootFolder, protected ICommentsManager $commentsManager, protected IURLGenerator $url, - protected IUserManager $userManager + protected IUserManager $userManager, ) { } diff --git a/apps/comments/lib/Search/LegacyProvider.php b/apps/comments/lib/Search/LegacyProvider.php index 3dbc51bbf38..a269c418d06 100644 --- a/apps/comments/lib/Search/LegacyProvider.php +++ b/apps/comments/lib/Search/LegacyProvider.php @@ -14,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 { @@ -26,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) { @@ -85,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 f9bdc71f0a3..7478c110d63 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -28,10 +29,6 @@ class Result extends BaseResult { /** * @deprecated 20.0.0 */ - public string $authorName; - /** - * @deprecated 20.0.0 - */ public $path; /** * @deprecated 20.0.0 @@ -45,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( @@ -56,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); } |