aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2022-12-19 10:46:39 +0100
committerGitHub <noreply@github.com>2022-12-19 10:46:39 +0100
commitcbbb0712db0f33a41ef66ae59d5c70ba1e23748f (patch)
treedb09b311f4a6a62451dd25db25ae9f8e80a3064c
parent884da19198d15a764487e6a6d615968c0e63203d (diff)
parente553cd1bb9cec6bf6200298bcca6637e81163953 (diff)
downloadnextcloud-server-cbbb0712db0f33a41ef66ae59d5c70ba1e23748f.tar.gz
nextcloud-server-cbbb0712db0f33a41ef66ae59d5c70ba1e23748f.zip
Merge pull request #34807 from nextcloud/fix/compute-notification-parsed-subject
Compute notification parsed subject from rich subject when possible
-rw-r--r--apps/comments/lib/Activity/Provider.php12
-rw-r--r--apps/comments/lib/Notification/Notifier.php19
-rw-r--r--apps/comments/tests/Unit/Notification/NotifierTest.php26
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Base.php18
-rw-r--r--apps/dav/lib/CardDAV/Activity/Provider/Base.php16
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php8
-rw-r--r--apps/federatedfilesharing/lib/Notifier.php9
-rw-r--r--apps/files/lib/Activity/FavoriteProvider.php3
-rw-r--r--apps/files/lib/Activity/Provider.php17
-rw-r--r--apps/files/lib/Notification/Notifier.php33
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Base.php20
-rw-r--r--apps/files_sharing/lib/Notification/Notifier.php10
-rw-r--r--apps/settings/lib/Activity/GroupProvider.php13
-rw-r--r--apps/settings/lib/Activity/Provider.php13
-rw-r--r--apps/sharebymail/lib/Activity.php93
-rw-r--r--apps/systemtags/lib/Activity/Provider.php1
-rw-r--r--apps/updatenotification/lib/Notification/Notifier.php16
-rw-r--r--lib/private/Activity/Event.php33
-rw-r--r--lib/private/Notification/Notification.php33
-rw-r--r--lib/public/Activity/IEvent.php12
-rw-r--r--lib/public/Notification/INotification.php12
21 files changed, 133 insertions, 284 deletions
diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php
index c6e55326580..f9a5971c7f3 100644
--- a/apps/comments/lib/Activity/Provider.php
+++ b/apps/comments/lib/Activity/Provider.php
@@ -31,12 +31,10 @@ use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Provider implements IProvider {
-
protected IFactory $languageFactory;
protected ?IL10N $l = null;
protected IUrlGenerator $url;
@@ -97,14 +95,12 @@ class Provider implements IProvider {
if ($event->getSubject() === 'add_comment_subject') {
if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) {
- $event->setParsedSubject($this->l->t('You commented'))
- ->setRichSubject($this->l->t('You commented'), []);
+ $event->setRichSubject($this->l->t('You commented'), []);
} else {
$author = $this->generateUserParameter($subjectParameters['actor']);
- $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']]))
- ->setRichSubject($this->l->t('{author} commented'), [
- 'author' => $author,
- ]);
+ $event->setRichSubject($this->l->t('{author} commented'), [
+ 'author' => $author,
+ ]);
}
} else {
throw new \InvalidArgumentException();
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php
index 4ddb7295bfe..59f1ad5da5f 100644
--- a/apps/comments/lib/Notification/Notifier.php
+++ b/apps/comments/lib/Notification/Notifier.php
@@ -29,7 +29,6 @@ use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\Files\IRootFolder;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
@@ -37,7 +36,6 @@ use OCP\Notification\INotification;
use OCP\Notification\INotifier;
class Notifier implements INotifier {
-
protected IFactory $l10nFactory;
protected IRootFolder $rootFolder;
protected ICommentsManager $commentsManager;
@@ -147,9 +145,7 @@ class Notifier implements INotifier {
}
[$message, $messageParameters] = $this->commentToRichMessage($comment);
$notification->setRichSubject($subject, $subjectParameters)
- ->setParsedSubject($this->richToParsed($subject, $subjectParameters))
->setRichMessage($message, $messageParameters)
- ->setParsedMessage($this->richToParsed($message, $messageParameters))
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')))
->setLink($this->url->linkToRouteAbsolute(
'comments.Notifications.view',
@@ -205,19 +201,4 @@ class Notifier implements INotifier {
}
return [$message, $messageParameters];
}
-
- public function richToParsed(string $message, array $parameters): string {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- if ($parameter['type'] === 'user') {
- $replacements[] = '@' . $parameter['name'];
- } elseif ($parameter['type'] === 'file') {
- $replacements[] = $parameter['path'];
- } else {
- $replacements[] = $parameter['name'];
- }
- }
- return str_replace($placeholders, $replacements, $message);
- }
}
diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php
index ecd22ffd9e3..9281bb99fe8 100644
--- a/apps/comments/tests/Unit/Notification/NotifierTest.php
+++ b/apps/comments/tests/Unit/Notification/NotifierTest.php
@@ -35,7 +35,6 @@ use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
@@ -43,7 +42,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotifierTest extends TestCase {
-
/** @var Notifier */
protected $notifier;
/** @var IFactory|MockObject */
@@ -135,10 +133,8 @@ class NotifierTest extends TestCase {
->method('getSubjectParameters')
->willReturn(['files', '678']);
$this->notification
- ->expects($this->once())
- ->method('setParsedSubject')
- ->with($message)
- ->willReturnSelf();
+ ->expects($this->never())
+ ->method('setParsedSubject');
$this->notification
->expects($this->once())
->method('setRichSubject')
@@ -150,10 +146,8 @@ class NotifierTest extends TestCase {
->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
->willReturnSelf();
$this->notification
- ->expects($this->once())
- ->method('setParsedMessage')
- ->with('Hi @Your name!')
- ->willReturnSelf();
+ ->expects($this->never())
+ ->method('setParsedMessage');
$this->notification
->expects($this->once())
->method('setIcon')
@@ -256,10 +250,8 @@ class NotifierTest extends TestCase {
->method('getSubjectParameters')
->willReturn(['files', '678']);
$this->notification
- ->expects($this->once())
- ->method('setParsedSubject')
- ->with($message)
- ->willReturnSelf();
+ ->expects($this->never())
+ ->method('setParsedSubject');
$this->notification
->expects($this->once())
->method('setRichSubject')
@@ -271,10 +263,8 @@ class NotifierTest extends TestCase {
->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
->willReturnSelf();
$this->notification
- ->expects($this->once())
- ->method('setParsedMessage')
- ->with('Hi @Your name!')
- ->willReturnSelf();
+ ->expects($this->never())
+ ->method('setParsedMessage');
$this->notification
->expects($this->once())
->method('setIcon')
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Base.php b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
index 672129a8311..841011574d0 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
@@ -30,11 +30,9 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
abstract class Base implements IProvider {
-
/** @var IUserManager */
protected $userManager;
@@ -58,20 +56,8 @@ abstract class Base implements IProvider {
$this->url = $urlGenerator;
}
- /**
- * @param IEvent $event
- * @param string $subject
- * @param array $parameters
- */
- protected function setSubjects(IEvent $event, $subject, array $parameters) {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
+ $event->setRichSubject($subject, $parameters);
}
/**
diff --git a/apps/dav/lib/CardDAV/Activity/Provider/Base.php b/apps/dav/lib/CardDAV/Activity/Provider/Base.php
index 3e7a966c08a..a59c3b57262 100644
--- a/apps/dav/lib/CardDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CardDAV/Activity/Provider/Base.php
@@ -32,11 +32,9 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
abstract class Base implements IProvider {
-
/** @var IUserManager */
protected $userManager;
@@ -60,20 +58,8 @@ abstract class Base implements IProvider {
$this->url = $urlGenerator;
}
- /**
- * @param IEvent $event
- * @param string $subject
- * @param array $parameters
- */
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ $event->setRichSubject($subject, $parameters);
}
/**
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
index 9e1e02189f5..e4622336d74 100644
--- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
+++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
@@ -32,13 +32,11 @@ use OCP\Activity\IProvider;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class BaseTest extends TestCase {
-
/** @var IUserManager|MockObject */
protected $userManager;
@@ -85,10 +83,8 @@ class BaseTest extends TestCase {
->method('setRichSubject')
->with($subject, $parameters)
->willReturnSelf();
- $event->expects($this->once())
- ->method('setParsedSubject')
- ->with($parsedSubject)
- ->willReturnSelf();
+ $event->expects($this->never())
+ ->method('setParsedSubject');
$this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]);
}
diff --git a/apps/federatedfilesharing/lib/Notifier.php b/apps/federatedfilesharing/lib/Notifier.php
index 5e57b77b64a..87c05e19e4b 100644
--- a/apps/federatedfilesharing/lib/Notifier.php
+++ b/apps/federatedfilesharing/lib/Notifier.php
@@ -108,10 +108,6 @@ class Notifier implements INotifier {
$params[3] = $remoteInitiator['name'] . '@' . $remoteInitiator['server'];
$params[4] = $remoteOwner['name'] . '@' . $remoteOwner['server'];
- $notification->setParsedSubject(
- $l->t('You received "%3$s" as a remote share from %4$s (%1$s) (on behalf of %5$s (%2$s))', $params)
- );
-
$notification->setRichSubject(
$l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'),
[
@@ -128,11 +124,6 @@ class Notifier implements INotifier {
$remoteOwner = $this->createRemoteUser($params[0]);
$params[3] = $remoteOwner['name'] . '@' . $remoteOwner['server'];
- $notification->setParsedSubject(
- $l->t('You received "%3$s" as a remote share from %4$s (%1$s)', $params)
- );
-
-
$notification->setRichSubject(
$l->t('You received {share} as a remote share from {user}'),
[
diff --git a/apps/files/lib/Activity/FavoriteProvider.php b/apps/files/lib/Activity/FavoriteProvider.php
index a1c08370e4e..9c7018e6a5c 100644
--- a/apps/files/lib/Activity/FavoriteProvider.php
+++ b/apps/files/lib/Activity/FavoriteProvider.php
@@ -172,7 +172,6 @@ class FavoriteProvider implements IProvider {
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]),
];
- $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject))
- ->setRichSubject($subject, ['file' => $parameter]);
+ $event->setRichSubject($subject, ['file' => $parameter]);
}
}
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php
index c21e8f9ad16..2cfd48ede3b 100644
--- a/apps/files/lib/Activity/Provider.php
+++ b/apps/files/lib/Activity/Provider.php
@@ -38,12 +38,10 @@ use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Provider implements IProvider {
-
/** @var IFactory */
protected $languageFactory;
@@ -306,19 +304,8 @@ class Provider implements IProvider {
return strlen($filename) > 0 && $filename[0] === '.';
}
- protected function setSubjects(IEvent $event, $subject, array $parameters) {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- if ($parameter['type'] === 'file') {
- $replacements[] = $parameter['path'];
- } else {
- $replacements[] = $parameter['name'];
- }
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
+ $event->setRichSubject($subject, $parameters);
}
/**
diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php
index 1a7a3726229..90784749b27 100644
--- a/apps/files/lib/Notification/Notifier.php
+++ b/apps/files/lib/Notification/Notifier.php
@@ -41,7 +41,6 @@ use OCP\Notification\INotification;
use OCP\Notification\INotifier;
class Notifier implements INotifier, IDismissableNotifier {
-
/** @var IFactory */
protected $l10nFactory;
@@ -151,7 +150,6 @@ class Notifier implements INotifier, IDismissableNotifier {
'name' => $sourceUser->getDisplayName(),
],
])
- ->setParsedSubject(str_replace('{user}', $sourceUser->getDisplayName(), $l->t('Incoming ownership transfer from {user}')))
->setRichMessage(
$l->t("Do you want to accept {path}?\n\nNote: The transfer process after accepting may take up to 1 hour."),
[
@@ -160,20 +158,17 @@ class Notifier implements INotifier, IDismissableNotifier {
'id' => $param['targetUser'] . '::' . $param['nodeName'],
'name' => $param['nodeName'],
]
- ])
- ->setParsedMessage(str_replace('{path}', $param['nodeName'], $l->t("Do you want to accept {path}?\n\nNote: The transfer process after accepting may take up to 1 hour.")));
+ ]);
return $notification;
}
- public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification {
+ public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();
$targetUser = $this->getUser($param['targetUser']);
$notification->setRichSubject($l->t('Ownership transfer failed'))
- ->setParsedSubject($l->t('Ownership transfer failed'))
-
->setRichMessage(
$l->t('Your ownership transfer of {path} to {user} failed.'),
[
@@ -187,19 +182,16 @@ class Notifier implements INotifier, IDismissableNotifier {
'id' => $targetUser->getUID(),
'name' => $targetUser->getDisplayName(),
],
- ])
- ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $targetUser->getDisplayName()], $l->t('Your ownership transfer of {path} to {user} failed.')));
+ ]);
return $notification;
}
- public function handleTransferOwnershipFailedTarget(INotification $notification, string $languageCode): INotification {
+ public function handleTransferOwnershipFailedTarget(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();
$sourceUser = $this->getUser($param['sourceUser']);
$notification->setRichSubject($l->t('Ownership transfer failed'))
- ->setParsedSubject($l->t('Ownership transfer failed'))
-
->setRichMessage(
$l->t('The ownership transfer of {path} from {user} failed.'),
[
@@ -213,20 +205,17 @@ class Notifier implements INotifier, IDismissableNotifier {
'id' => $sourceUser->getUID(),
'name' => $sourceUser->getDisplayName(),
],
- ])
- ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $sourceUser->getDisplayName()], $l->t('The ownership transfer of {path} from {user} failed.')));
+ ]);
return $notification;
}
- public function handleTransferOwnershipDoneSource(INotification $notification, string $languageCode): INotification {
+ public function handleTransferOwnershipDoneSource(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();
$targetUser = $this->getUser($param['targetUser']);
$notification->setRichSubject($l->t('Ownership transfer done'))
- ->setParsedSubject($l->t('Ownership transfer done'))
-
->setRichMessage(
$l->t('Your ownership transfer of {path} to {user} has completed.'),
[
@@ -240,20 +229,17 @@ class Notifier implements INotifier, IDismissableNotifier {
'id' => $targetUser->getUID(),
'name' => $targetUser->getDisplayName(),
],
- ])
- ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $targetUser->getDisplayName()], $l->t('Your ownership transfer of {path} to {user} has completed.')));
+ ]);
return $notification;
}
- public function handleTransferOwnershipDoneTarget(INotification $notification, string $languageCode): INotification {
+ public function handleTransferOwnershipDoneTarget(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();
$sourceUser = $this->getUser($param['sourceUser']);
$notification->setRichSubject($l->t('Ownership transfer done'))
- ->setParsedSubject($l->t('Ownership transfer done'))
-
->setRichMessage(
$l->t('The ownership transfer of {path} from {user} has completed.'),
[
@@ -267,8 +253,7 @@ class Notifier implements INotifier, IDismissableNotifier {
'id' => $sourceUser->getUID(),
'name' => $sourceUser->getDisplayName(),
],
- ])
- ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $sourceUser->getDisplayName()], $l->t('The ownership transfer of {path} from {user} has completed.')));
+ ]);
return $notification;
}
diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php
index ca5b9b55b62..4a2c6ac919e 100644
--- a/apps/files_sharing/lib/Activity/Providers/Base.php
+++ b/apps/files_sharing/lib/Activity/Providers/Base.php
@@ -31,12 +31,10 @@ use OCP\Contacts\IManager as IContactsManager;
use OCP\Federation\ICloudIdManager;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
abstract class Base implements IProvider {
-
/** @var IFactory */
protected $languageFactory;
@@ -124,24 +122,10 @@ abstract class Base implements IProvider {
abstract protected function parseLongVersion(IEvent $event, IEvent $previousEvent = null);
/**
- * @param IEvent $event
- * @param string $subject
- * @param array $parameters
* @throws \InvalidArgumentException
*/
- protected function setSubjects(IEvent $event, $subject, array $parameters) {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- if ($parameter['type'] === 'file') {
- $replacements[] = $parameter['path'];
- } else {
- $replacements[] = $parameter['name'];
- }
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
+ $event->setRichSubject($subject, $parameters);
}
/**
diff --git a/apps/files_sharing/lib/Notification/Notifier.php b/apps/files_sharing/lib/Notification/Notifier.php
index 58f2a60fcdd..455d0fd66fc 100644
--- a/apps/files_sharing/lib/Notification/Notifier.php
+++ b/apps/files_sharing/lib/Notification/Notifier.php
@@ -132,7 +132,6 @@ class Notifier implements INotifier {
$notification
->setParsedSubject($l->t('Share will expire tomorrow'))
- ->setParsedMessage($l->t('One or more of your shares will expire tomorrow'))
->setRichMessage(
$l->t('Your share of {node} will expire tomorrow'),
[
@@ -232,14 +231,7 @@ class Notifier implements INotifier {
throw new \InvalidArgumentException('Invalid subject');
}
- $placeholders = $replacements = [];
- foreach ($subjectParameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
- }
-
- $notification->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $subjectParameters)
+ $notification->setRichSubject($subject, $subjectParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
$acceptAction = $notification->createAction();
diff --git a/apps/settings/lib/Activity/GroupProvider.php b/apps/settings/lib/Activity/GroupProvider.php
index 466bb9abeee..52798d2e428 100644
--- a/apps/settings/lib/Activity/GroupProvider.php
+++ b/apps/settings/lib/Activity/GroupProvider.php
@@ -30,7 +30,6 @@ use OCP\Activity\IProvider;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory as L10nFactory;
@@ -123,20 +122,10 @@ class GroupProvider implements IProvider {
}
/**
- * @param IEvent $event
- * @param string $subject
- * @param array $parameters
* @throws \InvalidArgumentException
*/
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ $event->setRichSubject($subject, $parameters);
}
/**
diff --git a/apps/settings/lib/Activity/Provider.php b/apps/settings/lib/Activity/Provider.php
index 7d8a7f0da9a..85ebd3e2abd 100644
--- a/apps/settings/lib/Activity/Provider.php
+++ b/apps/settings/lib/Activity/Provider.php
@@ -33,7 +33,6 @@ use OCP\Activity\IManager;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
@@ -186,20 +185,10 @@ class Provider implements IProvider {
}
/**
- * @param IEvent $event
- * @param string $subject
- * @param array $parameters
* @throws \InvalidArgumentException
*/
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
- $placeholders = $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
- }
-
- $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $parameters);
+ $event->setRichSubject($subject, $parameters);
}
protected function generateUserParameter(string $uid): array {
diff --git a/apps/sharebymail/lib/Activity.php b/apps/sharebymail/lib/Activity.php
index 3693455dda4..d1f15eb0e54 100644
--- a/apps/sharebymail/lib/Activity.php
+++ b/apps/sharebymail/lib/Activity.php
@@ -31,12 +31,10 @@ use OCP\Activity\IProvider;
use OCP\Contacts\IManager as IContactsManager;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Activity implements IProvider {
-
/** @var IFactory */
protected $languageFactory;
@@ -115,72 +113,54 @@ class Activity implements IProvider {
$parsedParameters = $this->getParsedParameters($event);
if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
- $event->setParsedSubject($this->l->t('Shared with %1$s', [
- $parsedParameters['email']['name'],
- ]))
- ->setRichSubject($this->l->t('Shared with {email}'), [
- 'email' => $parsedParameters['email'],
- ]);
+ $event->setRichSubject($this->l->t('Shared with {email}'), [
+ 'email' => $parsedParameters['email'],
+ ]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
- $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
- $parsedParameters['email']['name'],
- $parsedParameters['actor']['name'],
- ]))
- ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
- 'email' => $parsedParameters['email'],
- 'actor' => $parsedParameters['actor'],
- ]);
+ $event->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
+ 'email' => $parsedParameters['email'],
+ 'actor' => $parsedParameters['actor'],
+ ]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
- $event->setParsedSubject($this->l->t('Unshared from %1$s', [
- $parsedParameters['email']['name'],
- ]))
- ->setRichSubject($this->l->t('Unshared from {email}'), [
- 'email' => $parsedParameters['email'],
- ]);
+ $event->setRichSubject($this->l->t('Unshared from {email}'), [
+ 'email' => $parsedParameters['email'],
+ ]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
- $event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [
- $parsedParameters['email']['name'],
- $parsedParameters['actor']['name'],
- ]))
- ->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [
- 'email' => $parsedParameters['email'],
- 'actor' => $parsedParameters['actor'],
- ]);
+ $event->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [
+ 'email' => $parsedParameters['email'],
+ 'actor' => $parsedParameters['actor'],
+ ]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
- $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [
- $parsedParameters['email']['name']
- ]))
- ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [
- 'email' => $parsedParameters['email']
- ]);
+ $event->setRichSubject($this->l->t('Password for mail share sent to {email}'), [
+ 'email' => $parsedParameters['email']
+ ]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
- $event->setParsedSubject($this->l->t('Password for mail share sent to you'))
- ->setRichSubject($this->l->t('Password for mail share sent to you'));
+ $event->setRichSubject($this->l->t('Password for mail share sent to you'));
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
@@ -203,67 +183,42 @@ class Activity implements IProvider {
$parsedParameters = $this->getParsedParameters($event);
if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) {
- $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [
- $parsedParameters['file']['path'],
- $parsedParameters['email']['name'],
- ]))
- ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters);
+ $event->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
- $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
- $parsedParameters['file']['path'],
- $parsedParameters['email']['name'],
- $parsedParameters['actor']['name'],
- ]))
- ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters);
+ $event->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
- $event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [
- $parsedParameters['file']['path'],
- $parsedParameters['email']['name'],
- ]))
- ->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters);
+ $event->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
- $event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [
- $parsedParameters['file']['path'],
- $parsedParameters['email']['name'],
- $parsedParameters['actor']['name'],
- ]))
- ->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters);
+ $event->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
- $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [
- $parsedParameters['file']['path'],
- $parsedParameters['email']['name']
- ]))
- ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters);
+ $event->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
- $event->setParsedSubject(
- $this->l->t('Password to access %1$s was sent to you',
- [$parsedParameters['file']['path']]))
- ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters);
+ $event->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
diff --git a/apps/systemtags/lib/Activity/Provider.php b/apps/systemtags/lib/Activity/Provider.php
index 16a5687fc81..63e000325d4 100644
--- a/apps/systemtags/lib/Activity/Provider.php
+++ b/apps/systemtags/lib/Activity/Provider.php
@@ -28,7 +28,6 @@ use OCP\Activity\IManager;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index bfbcc203480..abba20f993b 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -39,7 +39,6 @@ use OCP\Notification\INotifier;
use OCP\Util;
class Notifier implements INotifier {
-
/** @var IURLGenerator */
protected $url;
@@ -141,14 +140,13 @@ class Notifier implements INotifier {
$this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
}
- $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]))
- ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [
- 'app' => [
- 'type' => 'app',
- 'id' => $notification->getObjectType(),
- 'name' => $appName,
- ]
- ]);
+ $notification->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [
+ 'app' => [
+ 'type' => 'app',
+ 'id' => $notification->getObjectType(),
+ 'name' => $appName,
+ ]
+ ]);
if ($this->isAdmin()) {
$notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType());
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php
index fd0c0afd9d8..cc1135cf179 100644
--- a/lib/private/Activity/Event.php
+++ b/lib/private/Activity/Event.php
@@ -33,7 +33,6 @@ use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator;
class Event implements IEvent {
-
/** @var string */
protected $app = '';
/** @var string */
@@ -269,10 +268,38 @@ class Event implements IEvent {
$this->subjectRich = $subject;
$this->subjectRichParameters = $parameters;
+ if ($this->subjectParsed === '') {
+ $this->subjectParsed = $this->richToParsed($subject, $parameters);
+ }
+
return $this;
}
/**
+ * @throws \InvalidArgumentException if a parameter has no name or no type
+ */
+ private function richToParsed(string $message, array $parameters): string {
+ $placeholders = [];
+ $replacements = [];
+ foreach ($parameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ foreach (['name','type'] as $requiredField) {
+ if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
+ throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
+ }
+ }
+ if ($parameter['type'] === 'user') {
+ $replacements[] = '@' . $parameter['name'];
+ } elseif ($parameter['type'] === 'file') {
+ $replacements[] = $parameter['path'] ?? $parameter['name'];
+ } else {
+ $replacements[] = $parameter['name'];
+ }
+ }
+ return str_replace($placeholders, $replacements, $message);
+ }
+
+ /**
* @return string
* @since 11.0.0
*/
@@ -350,6 +377,10 @@ class Event implements IEvent {
$this->messageRich = $message;
$this->messageRichParameters = $parameters;
+ if ($this->messageParsed === '') {
+ $this->messageParsed = $this->richToParsed($message, $parameters);
+ }
+
return $this;
}
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php
index 3e5cf1d6934..2291c4ae34f 100644
--- a/lib/private/Notification/Notification.php
+++ b/lib/private/Notification/Notification.php
@@ -32,7 +32,6 @@ use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator;
class Notification implements INotification {
-
/** @var IValidator */
protected $richValidator;
@@ -296,10 +295,38 @@ class Notification implements INotification {
$this->subjectRich = $subject;
$this->subjectRichParameters = $parameters;
+ if ($this->subjectParsed === '') {
+ $this->subjectParsed = $this->richToParsed($subject, $parameters);
+ }
+
return $this;
}
/**
+ * @throws \InvalidArgumentException if a parameter has no name or no type
+ */
+ private function richToParsed(string $message, array $parameters): string {
+ $placeholders = [];
+ $replacements = [];
+ foreach ($parameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ foreach (['name','type'] as $requiredField) {
+ if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
+ throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
+ }
+ }
+ if ($parameter['type'] === 'user') {
+ $replacements[] = '@' . $parameter['name'];
+ } elseif ($parameter['type'] === 'file') {
+ $replacements[] = $parameter['path'] ?? $parameter['name'];
+ } else {
+ $replacements[] = $parameter['name'];
+ }
+ }
+ return str_replace($placeholders, $replacements, $message);
+ }
+
+ /**
* @return string
* @since 11.0.0
*/
@@ -386,6 +413,10 @@ class Notification implements INotification {
$this->messageRich = $message;
$this->messageRichParameters = $parameters;
+ if ($this->messageParsed === '') {
+ $this->messageParsed = $this->richToParsed($message, $parameters);
+ }
+
return $this;
}
diff --git a/lib/public/Activity/IEvent.php b/lib/public/Activity/IEvent.php
index 1e3c1deef26..4c47cc47a3f 100644
--- a/lib/public/Activity/IEvent.php
+++ b/lib/public/Activity/IEvent.php
@@ -103,9 +103,7 @@ interface IEvent {
* HTML is not allowed in the parsed subject and will be escaped
* automatically by the clients. You can use the RichObjectString system
* provided by the Nextcloud server to highlight important parameters via
- * the setRichSubject method, but make sure, that a plain text message is
- * always set via setParsedSubject, to support clients which can not handle
- * rich strings.
+ * the setRichSubject method.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -128,8 +126,6 @@ interface IEvent {
* HTML is not allowed in the rich subject and will be escaped automatically
* by the clients, but you can use the RichObjectString system provided by
* the Nextcloud server to highlight important parameters.
- * Also make sure, that a plain text subject is always set via
- * setParsedSubject, to support clients which can not handle rich strings.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -170,9 +166,7 @@ interface IEvent {
* HTML is not allowed in the parsed message and will be escaped
* automatically by the clients. You can use the RichObjectString system
* provided by the Nextcloud server to highlight important parameters via
- * the setRichMessage method, but make sure, that a plain text message is
- * always set via setParsedMessage, to support clients which can not handle
- * rich strings.
+ * the setRichMessage method.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -195,8 +189,6 @@ interface IEvent {
* HTML is not allowed in the rich message and will be escaped automatically
* by the clients, but you can use the RichObjectString system provided by
* the Nextcloud server to highlight important parameters.
- * Also make sure, that a plain text message is always set via
- * setParsedMessage, to support clients which can not handle rich strings.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
diff --git a/lib/public/Notification/INotification.php b/lib/public/Notification/INotification.php
index 511f65955f5..0c6625e346d 100644
--- a/lib/public/Notification/INotification.php
+++ b/lib/public/Notification/INotification.php
@@ -121,9 +121,7 @@ interface INotification {
* HTML is not allowed in the parsed subject and will be escaped
* automatically by the clients. You can use the RichObjectString system
* provided by the Nextcloud server to highlight important parameters via
- * the setRichSubject method, but make sure, that a plain text message is
- * always set via setParsedSubject, to support clients which can not handle
- * rich strings.
+ * the setRichSubject method.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -146,8 +144,6 @@ interface INotification {
* HTML is not allowed in the rich subject and will be escaped automatically
* by the clients, but you can use the RichObjectString system provided by
* the Nextcloud server to highlight important parameters.
- * Also make sure, that a plain text subject is always set via
- * setParsedSubject, to support clients which can not handle rich strings.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -198,9 +194,7 @@ interface INotification {
* HTML is not allowed in the parsed message and will be escaped
* automatically by the clients. You can use the RichObjectString system
* provided by the Nextcloud server to highlight important parameters via
- * the setRichMessage method, but make sure, that a plain text message is
- * always set via setParsedMessage, to support clients which can not handle
- * rich strings.
+ * the setRichMessage method.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*
@@ -223,8 +217,6 @@ interface INotification {
* HTML is not allowed in the rich message and will be escaped automatically
* by the clients, but you can use the RichObjectString system provided by
* the Nextcloud server to highlight important parameters.
- * Also make sure, that a plain text message is always set via
- * setParsedMessage, to support clients which can not handle rich strings.
*
* See https://github.com/nextcloud/server/issues/1706 for more information.
*