diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-22 14:29:01 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-23 11:19:41 +0100 |
commit | 56cfd0a6e408b1350d490e9bea35fadcbde2bdb4 (patch) | |
tree | 1423799cd8a2df90b4ac770328e4ef142e6b583c /apps/comments/lib | |
parent | 7b0b7e801f23e3115cfb43ea777171d0a443eb8c (diff) | |
download | nextcloud-server-56cfd0a6e408b1350d490e9bea35fadcbde2bdb4.tar.gz nextcloud-server-56cfd0a6e408b1350d490e9bea35fadcbde2bdb4.zip |
Set the rich object string for comment notifications
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php index 3838a18f9f1..15a3a1eab76 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -24,6 +24,7 @@ namespace OCA\Comments\Notification; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; use OCP\Files\Folder; +use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\INotification; @@ -40,18 +41,23 @@ class Notifier implements INotifier { /** @var ICommentsManager */ protected $commentsManager; - /** @var IUserManager */ + /** @var IURLGenerator */ + protected $url; + + /** @var IUserManager */ protected $userManager; public function __construct( IFactory $l10nFactory, Folder $userFolder, ICommentsManager $commentsManager, + IURLGenerator $url, IUserManager $userManager ) { $this->l10nFactory = $l10nFactory; $this->userFolder = $userFolder; $this->commentsManager = $commentsManager; + $this->url = $url; $this->userManager = $userManager; } @@ -63,7 +69,7 @@ class Notifier implements INotifier { */ public function prepare(INotification $notification, $languageCode) { if($notification->getApp() !== 'comments') { - throw new \InvalidArgumentException(); + throw new \InvalidArgumentException(); } try { $comment = $this->commentsManager->get($notification->getObjectId()); @@ -80,6 +86,7 @@ class Notifier implements INotifier { $displayName = $commenter->getDisplayName(); } } + switch($notification->getSubject()) { case 'mention': $parameters = $notification->getSubjectParameters(); @@ -90,19 +97,48 @@ class Notifier implements INotifier { if(empty($nodes)) { throw new \InvalidArgumentException('Cannot resolve file id to Node instance'); } - $fileName = $nodes[0]->getName(); - if($isDeletedActor) { - $subject = (string) $l->t( - 'A (now) deleted user mentioned you in a comment on "%s".', - [ $fileName ] - ); + $node = $nodes[0]; + + if ($isDeletedActor) { + $notification->setParsedSubject($l->t( + 'A (now) deleted user mentioned you in a comment on “%s”', + [$node->getName()] + )) + ->setRichSubject( + $l->t('A (now) deleted user mentioned you in a comment on “{file}”'), + [ + 'file' => [ + 'type' => 'file', + 'id' => $comment->getObjectId(), + 'name' => $node->getName(), + 'path' => $node->getPath(), + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), + ], + ] + ); } else { - $subject = (string) $l->t( - '%s mentioned you in a comment on "%s".', - [ $displayName, $fileName ] - ); + $notification->setParsedSubject($l->t( + '%1$s mentioned you in a comment on “%2$s”', + [$displayName, $node->getName()] + )) + ->setRichSubject( + $l->t('{user} mentioned you in a comment on “{file}”'), + [ + 'user' => [ + 'type' => 'user', + 'id' => $comment->getActorId(), + 'name' => $displayName, + ], + 'file' => [ + 'type' => 'file', + 'id' => $comment->getObjectId(), + 'name' => $node->getName(), + 'path' => $node->getPath(), + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), + ], + ] + ); } - $notification->setParsedSubject($subject); return $notification; break; |