aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/lib/Activity
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments/lib/Activity')
-rw-r--r--apps/comments/lib/Activity/Filter.php66
-rw-r--r--apps/comments/lib/Activity/Listener.php66
-rw-r--r--apps/comments/lib/Activity/Provider.php76
-rw-r--r--apps/comments/lib/Activity/Setting.php90
4 files changed, 81 insertions, 217 deletions
diff --git a/apps/comments/lib/Activity/Filter.php b/apps/comments/lib/Activity/Filter.php
index efd8d5140ae..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;
@@ -27,64 +11,40 @@ use OCP\IL10N;
use OCP\IURLGenerator;
class Filter implements IFilter {
-
- /** @var IL10N */
- protected $l;
-
- /** @var IURLGenerator */
- protected $url;
-
- public function __construct(IL10N $l, IURLGenerator $url) {
- $this->l = $l;
- $this->url = $url;
+ public function __construct(
+ protected IL10N $l,
+ protected IURLGenerator $url,
+ ) {
}
- /**
- * @return string Lowercase a-z only identifier
- * @since 11.0.0
- */
- public function getIdentifier() {
+ public function getIdentifier(): string {
return 'comments';
}
- /**
- * @return string A translated string
- * @since 11.0.0
- */
- public function getName() {
+ public function getName(): string {
return $this->l->t('Comments');
}
- /**
- * @return int
- * @since 11.0.0
- */
- public function getPriority() {
+ public function getPriority(): int {
return 40;
}
- /**
- * @return string Full URL to an icon, empty string when none is given
- * @since 11.0.0
- */
- public function getIcon() {
+ public function getIcon(): string {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'));
}
/**
* @param string[] $types
* @return string[] An array of allowed apps from which activities should be displayed
- * @since 11.0.0
*/
- public function filterTypes(array $types) {
+ public function filterTypes(array $types): array {
return $types;
}
/**
* @return string[] An array of allowed apps from which activities should be displayed
- * @since 11.0.0
*/
- public function allowedApps() {
+ public function allowedApps(): array {
return ['comments'];
}
}
diff --git a/apps/comments/lib/Activity/Listener.php b/apps/comments/lib/Activity/Listener.php
index 69315b6ac00..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;
@@ -35,37 +18,20 @@ use OCP\IUserSession;
use OCP\Share\IShareHelper;
class Listener {
- protected IManager $activityManager;
- protected IUserSession $session;
- protected IAppManager $appManager;
- protected IMountProviderCollection $mountCollection;
- protected IRootFolder $rootFolder;
- protected IShareHelper $shareHelper;
-
- /**
- * Listener constructor.
- */
- public function __construct(IManager $activityManager,
- IUserSession $session,
- IAppManager $appManager,
- IMountProviderCollection $mountCollection,
- IRootFolder $rootFolder,
- IShareHelper $shareHelper) {
- $this->activityManager = $activityManager;
- $this->session = $session;
- $this->appManager = $appManager;
- $this->mountCollection = $mountCollection;
- $this->rootFolder = $rootFolder;
- $this->shareHelper = $shareHelper;
+ public function __construct(
+ protected IManager $activityManager,
+ protected IUserSession $session,
+ protected IAppManager $appManager,
+ protected IMountProviderCollection $mountCollection,
+ protected IRootFolder $rootFolder,
+ protected IShareHelper $shareHelper,
+ ) {
}
- /**
- * @param CommentsEvent $event
- */
- public function commentEvent(CommentsEvent $event) {
+ 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;
}
@@ -101,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(),
]);
@@ -113,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 f9a5971c7f3..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;
@@ -35,19 +18,15 @@ use OCP\IUserManager;
use OCP\L10N\IFactory;
class Provider implements IProvider {
- protected IFactory $languageFactory;
protected ?IL10N $l = null;
- protected IUrlGenerator $url;
- protected ICommentsManager $commentsManager;
- protected IUserManager $userManager;
- protected IManager $activityManager;
-
- public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) {
- $this->languageFactory = $languageFactory;
- $this->url = $url;
- $this->commentsManager = $commentsManager;
- $this->userManager = $userManager;
- $this->activityManager = $activityManager;
+
+ public function __construct(
+ protected IFactory $languageFactory,
+ protected IURLGenerator $url,
+ protected ICommentsManager $commentsManager,
+ protected IUserManager $userManager,
+ protected IManager $activityManager,
+ ) {
}
/**
@@ -55,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) {
+ 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);
@@ -76,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);
@@ -103,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);
@@ -135,7 +114,7 @@ class Provider implements IProvider {
]);
}
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
return $event;
@@ -168,10 +147,10 @@ class Provider implements IProvider {
return;
}
- $commentId = isset($messageParameters['commentId']) ? $messageParameters['commentId'] : $messageParameters[0];
+ $commentId = $messageParameters['commentId'] ?? $messageParameters[0];
try {
- $comment = $this->commentsManager->get((string) $commentId);
+ $comment = $this->commentsManager->get((string)$commentId);
$message = $comment->getMessage();
$mentionCount = 1;
@@ -182,7 +161,7 @@ class Provider implements IProvider {
}
$message = str_replace('@"' . $mention['id'] . '"', '{mention' . $mentionCount . '}', $message);
- if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) {
+ if (!str_contains($mention['id'], ' ') && !str_starts_with($mention['id'], 'guest/')) {
$message = str_replace('@' . $mention['id'], '{mention' . $mentionCount . '}', $message);
}
@@ -196,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 c0d91c244a6..7fbf4001b20 100644
--- a/apps/comments/lib/Activity/Setting.php
+++ b/apps/comments/lib/Activity/Setting.php
@@ -1,97 +1,53 @@
<?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 {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
+class Setting extends ActivitySettings {
+ public function __construct(
+ protected IL10N $l,
+ ) {
}
- /**
- * @return string Lowercase a-z and underscore only identifier
- * @since 11.0.0
- */
- public function getIdentifier() {
+ public function getIdentifier(): string {
return 'comments';
}
- /**
- * @return string A translated string
- * @since 11.0.0
- */
- public function getName() {
+ public function getName(): string {
return $this->l->t('<strong>Comments</strong> for files');
}
- /**
- * @return int whether the filter should be rather on the top or bottom of
- * the admin section. The filters are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
- * @since 11.0.0
- */
- public function getPriority() {
+ public function getGroupIdentifier() {
+ return 'files';
+ }
+
+ public function getGroupName() {
+ return $this->l->t('Files');
+ }
+
+ public function getPriority(): int {
return 50;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function canChangeStream() {
+ public function canChangeStream(): bool {
return true;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledStream() {
+ public function isDefaultEnabledStream(): bool {
return true;
}
- /**
- * @return bool True when the option can be changed for the mail
- * @since 11.0.0
- */
- public function canChangeMail() {
+ public function canChangeMail(): bool {
return true;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledMail() {
+ public function isDefaultEnabledMail(): bool {
return false;
}
}