Send notification on user mention
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user