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;
|
namespace OCA\Deck\Activity;
|
||||||
|
|
||||||
use OCA\Deck\Db\CardMapper;
|
use OCA\Deck\Db\CardMapper;
|
||||||
|
use OCA\Deck\Notification\NotificationHelper;
|
||||||
use OCP\Comments\CommentsEvent;
|
use OCP\Comments\CommentsEvent;
|
||||||
use \OCP\Comments\ICommentsEventHandler;
|
use \OCP\Comments\ICommentsEventHandler;
|
||||||
|
|
||||||
@@ -33,9 +34,11 @@ class CommentEventHandler implements ICommentsEventHandler {
|
|||||||
private $activityManager;
|
private $activityManager;
|
||||||
/** @var CardMapper */
|
/** @var CardMapper */
|
||||||
private $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->cardMapper = $cardMapper;
|
||||||
|
$this->notificationHelper = $notificationHelper;
|
||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +82,6 @@ class CommentEventHandler implements ICommentsEventHandler {
|
|||||||
* @param CommentsEvent $event
|
* @param CommentsEvent $event
|
||||||
*/
|
*/
|
||||||
private function notificationHandler(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\BoardMapper;
|
||||||
use OCA\Deck\Db\CardMapper;
|
use OCA\Deck\Db\CardMapper;
|
||||||
use OCA\Deck\Service\PermissionService;
|
use OCA\Deck\Service\PermissionService;
|
||||||
|
use OCP\Comments\IComment;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Notification\IManager;
|
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
|
* @param $boardId
|
||||||
* @return Board
|
* @return Board
|
||||||
|
|||||||
@@ -105,6 +105,31 @@ class Notifier implements INotifier {
|
|||||||
);
|
);
|
||||||
$notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . '');
|
$notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . '');
|
||||||
break;
|
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':
|
case 'board-shared':
|
||||||
$boardId = $notification->getObjectId();
|
$boardId = $notification->getObjectId();
|
||||||
$initiator = $this->userManager->get($params[1]);
|
$initiator = $this->userManager->get($params[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user