diff --git a/lib/Activity/CommentEventHandler.php b/lib/Activity/CommentEventHandler.php index 438d1d8b9..ec740e059 100644 --- a/lib/Activity/CommentEventHandler.php +++ b/lib/Activity/CommentEventHandler.php @@ -24,6 +24,7 @@ namespace OCA\Deck\Activity; use OCA\Deck\Db\CardMapper; +use OCA\Deck\Notification\NotificationHelper; use OCP\Comments\CommentsEvent; use \OCP\Comments\ICommentsEventHandler; @@ -33,9 +34,11 @@ class CommentEventHandler implements ICommentsEventHandler { private $activityManager; /** @var CardMapper */ private $cardMapper; + private $notificationHelper; - public function __construct(ActivityManager $activityManager, CardMapper $cardMapper) { + public function __construct(ActivityManager $activityManager, NotificationHelper $notificationHelper, CardMapper $cardMapper) { $this->cardMapper = $cardMapper; + $this->notificationHelper = $notificationHelper; $this->activityManager = $activityManager; } @@ -79,6 +82,6 @@ class CommentEventHandler implements ICommentsEventHandler { * @param CommentsEvent $event */ private function notificationHandler(CommentsEvent $event) { - + $this->notificationHelper->sendMention($event->getComment()); } } diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index e4a6f21ee..2526624d8 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -29,6 +29,7 @@ use OCA\Deck\Db\Board; use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\CardMapper; use OCA\Deck\Service\PermissionService; +use OCP\Comments\IComment; use OCP\IGroupManager; use OCP\IUser; use OCP\Notification\IManager; @@ -134,6 +135,22 @@ class NotificationHelper { } } + public function sendMention(IComment $comment) { + foreach ($comment->getMentions() as $mention) { + $card = $this->cardMapper->find($comment->getObjectId()); + $boardId = $this->cardMapper->findBoardId($card->getId()); + $notification = $this->notificationManager->createNotification(); + $notification + ->setApp('deck') + ->setUser((string) $mention['id']) + ->setDateTime(new DateTime()) + ->setObject('card', (string) $card->getId()) + ->setSubject('card-comment-mentioned', [$card->getTitle(), $boardId, $this->currentUser]) + ->setMessage($comment->getMessage()); + $this->notificationManager->notify($notification); + } + } + /** * @param $boardId * @return Board @@ -160,4 +177,4 @@ class NotificationHelper { return $notification; } -} \ No newline at end of file +} diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index fd54fe88b..b330fda06 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -105,6 +105,31 @@ class Notifier implements INotifier { ); $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); break; + case 'card-comment-mentioned': + $cardId = $notification->getObjectId(); + $boardId = $this->cardMapper->findBoardId($cardId); + $initiator = $this->userManager->get($params[2]); + if ($initiator !== null) { + $dn = $initiator->getDisplayName(); + } else { + $dn = $params[2]; + } + $notification->setParsedSubject( + (string) $l->t('%s has mentioned in a comment on "%s".', [$dn, $params[0]]) + ); + $notification->setRichSubject( + (string) $l->t('{user} has mentioned in a comment on "%s".', [$params[0]]), + [ + 'user' => [ + 'type' => 'user', + 'id' => $params[0], + 'name' => $dn, + ] + ] + ); + $notification->setParsedMessage($notification->getMessage()); + $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); + break; case 'board-shared': $boardId = $notification->getObjectId(); $initiator = $this->userManager->get($params[1]); @@ -131,4 +156,4 @@ class Notifier implements INotifier { } return $notification; } -} \ No newline at end of file +}