From 77472b978d49d4127a688b4bdd4d91e096a1ced1 Mon Sep 17 00:00:00 2001 From: Steav Date: Sun, 22 Jul 2018 13:41:56 +0200 Subject: [PATCH] Add notification on card assignment to user Signed-off-by: Steav --- l10n/de.js | 1 + l10n/de.json | 1 + l10n/de_DE.js | 1 + l10n/de_DE.json | 1 + lib/Notification/NotificationHelper.php | 18 ++++++++++++++++++ lib/Notification/Notifier.php | 12 ++++++++++++ lib/Service/CardService.php | 10 +++++++++- 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/l10n/de.js b/l10n/de.js index efc1010ce..93f055742 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -10,6 +10,7 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de.json b/l10n/de.json index 95c7a2b55..5b19f15cc 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -8,6 +8,7 @@ "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.js b/l10n/de_DE.js index 1ee8a819c..86dec14bf 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -10,6 +10,7 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchten Sie diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.json b/l10n/de_DE.json index b565c2a4c..a4c808953 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -9,6 +9,7 @@ "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", "Finished" : "Abgeschlossen", diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index b2d0a9aa9..e4a6f21ee 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -94,6 +94,24 @@ class NotificationHelper { $this->cardMapper->markNotified($card); } + public function sendCardAssigned($card, $userId) { + $boardId = $this->cardMapper->findBoardId($card->getId()); + $board = $this->getBoard($boardId); + + $notification = $this->notificationManager->createNotification(); + $notification + ->setApp('deck') + ->setUser((string) $userId) + ->setDateTime(new DateTime()) + ->setObject('card', $card->getId()) + ->setSubject('card-assigned', [ + $card->getTitle(), + $board->getTitle(), + $this->currentUser + ]); + $this->notificationManager->notify($notification); + } + /** * Send notifications that a board was shared with a user/group * diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 1049a8201..84ac2c5c9 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -73,6 +73,18 @@ class Notifier implements INotifier { $params = $notification->getSubjectParameters(); switch ($notification->getSubject()) { + case 'card-assigned': + $cardId = $notification->getObjectId(); + $boardId = $this->cardMapper->findBoardId($cardId); + $initiator = $this->userManager->get($params[2]); + if ($initiator !== null) { + $params[2] = $initiator->getDisplayName(); + } + $notification->setParsedSubject( + (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', $params) + ); + $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); + break; case 'card-overdue': $cardId = $notification->getObjectId(); $boardId = $this->cardMapper->findBoardId($cardId); diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 26fa3753c..83188de0b 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -29,6 +29,7 @@ use OCA\Deck\Db\Card; use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\Acl; use OCA\Deck\Db\StackMapper; +use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\NotFoundException; use OCA\Deck\StatusException; @@ -39,14 +40,16 @@ class CardService { private $stackMapper; private $permissionService; private $boardService; + private $notificationHelper; private $assignedUsersMapper; private $attachmentService; - public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService) { + public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, NotificationHelper $notificationHelper, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService) { $this->cardMapper = $cardMapper; $this->stackMapper = $stackMapper; $this->permissionService = $permissionService; $this->boardService = $boardService; + $this->notificationHelper = $notificationHelper; $this->assignedUsersMapper = $assignedUsersMapper; $this->attachmentService = $attachmentService; } @@ -202,6 +205,11 @@ class CardService { return false; } } + + /* Notify user about the card assignment */ + $card = $this->cardMapper->find($cardId); + $this->notificationHelper->sendCardAssigned($card, $userId); + $assignment = new AssignedUsers(); $assignment->setCardId($cardId); $assignment->setParticipant($userId);