diff options
Diffstat (limited to 'apps/comments/lib/Activity/Provider.php')
-rw-r--r-- | apps/comments/lib/Activity/Provider.php | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php index 2f0f8e314cb..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 { 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]), |