From 5c9fc601fc5a127f79b5e1c4cfe4d638cb0fe13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20R=C3=B6hrl?= Date: Wed, 3 Mar 2021 15:11:42 +0100 Subject: [PATCH] interactive notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Röhrl --- lib/Notification/Notifier.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 3ea422cf5..e52a13065 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -31,6 +31,7 @@ use OCP\L10N\IFactory; use OCP\Notification\AlreadyProcessedException; use OCP\Notification\INotification; use OCP\Notification\INotifier; +use OCP\Notification\IAction; class Notifier implements INotifier { /** @var IFactory */ @@ -120,6 +121,7 @@ class Notifier implements INotifier { ] ); $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification = $this->addActionButton($notification, $l->t('View card')); break; case 'card-overdue': $cardId = $notification->getObjectId(); @@ -131,6 +133,9 @@ class Notifier implements INotifier { (string) $l->t('The card "%s" on "%s" has reached its due date.', $params) ); $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification = $this->addActionButton($notification, $l->t('View card')); + // $notification = $this->addActionButton($notification, $l->t('Set due to tomorrow'), false); + $notification = $this->addActionButtonChangeDueDate($notification, $l->t('Remove due date'), false); break; case 'card-comment-mentioned': $cardId = $notification->getObjectId(); @@ -161,6 +166,7 @@ class Notifier implements INotifier { $notification->setParsedMessage($notification->getMessageParameters()['message']); } $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification = $this->addActionButton($notification, $l->t('View card')); break; case 'board-shared': $boardId = $notification->getObjectId(); @@ -187,8 +193,34 @@ class Notifier implements INotifier { ] ); $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/'); + $notification = $this->addActionButton($notification, $l->t('View board')); break; } return $notification; } + + protected function addActionButton(INotification $notification, string $label, bool $primary = true): INotification { + $action = $notification->createAction(); + $action->setLabel($label) + ->setParsedLabel($label) + ->setLink($notification->getLink(), IAction::TYPE_WEB) + ->setPrimary($primary); + + $notification->addParsedAction($action); + + return $notification; + } + + protected function addActionButtonChangeDueDate(INotification $notification, string $label, bool $primary = true): INotification { + $action = $notification->createAction(); + $action->setLabel($label) + ->setParsedLabel($label) + ->setLink($notification->getLink(), IAction::TYPE_WEB) + ->setPrimary($primary); + + $notification->addParsedAction($action); + + return $notification; + } + }