-
Notifications
You must be signed in to change notification settings - Fork 310
Rich object string parameters for notifications #2935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| use OCA\Deck\Db\BoardMapper; | ||
| use OCA\Deck\Db\CardMapper; | ||
| use OCA\Deck\Db\StackMapper; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUserManager; | ||
| use OCP\L10N\IFactory; | ||
|
|
@@ -41,6 +42,8 @@ class Notifier implements INotifier { | |
| protected $userManager; | ||
| /** @var CardMapper */ | ||
| protected $cardMapper; | ||
| /** @var StackMapper */ | ||
| protected $stackMapper; | ||
| /** @var BoardMapper */ | ||
| protected $boardMapper; | ||
|
|
||
|
|
@@ -49,12 +52,14 @@ public function __construct( | |
| IURLGenerator $url, | ||
| IUserManager $userManager, | ||
| CardMapper $cardMapper, | ||
| StackMapper $stackMapper, | ||
| BoardMapper $boardMapper | ||
| ) { | ||
| $this->l10nFactory = $l10nFactory; | ||
| $this->url = $url; | ||
| $this->userManager = $userManager; | ||
| $this->cardMapper = $cardMapper; | ||
| $this->stackMapper = $stackMapper; | ||
| $this->boardMapper = $boardMapper; | ||
| } | ||
|
|
||
|
|
@@ -100,6 +105,11 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| if (!$boardId) { | ||
| throw new AlreadyProcessedException(); | ||
| } | ||
|
|
||
| $card = $this->cardMapper->find($cardId); | ||
| $stackId = $card->getStackId(); | ||
| $stack = $this->stackMapper->find($stackId); | ||
|
|
||
| $initiator = $this->userManager->get($params[2]); | ||
| if ($initiator !== null) { | ||
| $dn = $initiator->getDisplayName(); | ||
|
|
@@ -110,8 +120,22 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn]) | ||
| ); | ||
| $notification->setRichSubject( | ||
| (string) $l->t('{user} has assigned the card "%s" on "%s" to you.', [$params[0], $params[1]]), | ||
| $l->t('{user} has assigned the card {deck-card} on {deck-board} to you.'), | ||
| [ | ||
| 'deck-card' => [ | ||
| 'type' => 'deck-card', | ||
| 'id' => $cardId, | ||
| 'name' => $params[0], | ||
| 'boardname' => $params[1], | ||
| 'stackname' => $stack->getTitle(), | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', | ||
| ], | ||
| 'deck-board' => [ | ||
| 'type' => 'deck-board', | ||
| 'id' => $boardId, | ||
| 'name' => $params[1], | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, | ||
| ], | ||
| 'user' => [ | ||
| 'type' => 'user', | ||
| 'id' => $params[2], | ||
|
|
@@ -127,9 +151,33 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| if (!$boardId) { | ||
| throw new AlreadyProcessedException(); | ||
| } | ||
|
|
||
| $card = $this->cardMapper->find($cardId); | ||
| $stackId = $card->getStackId(); | ||
| $stack = $this->stackMapper->find($stackId); | ||
|
|
||
| $notification->setParsedSubject( | ||
| (string) $l->t('The card "%s" on "%s" has reached its due date.', $params) | ||
| ); | ||
| $notification->setRichSubject( | ||
| $l->t('The card {deck-card} on {deck-board} has reached its due date.'), | ||
| [ | ||
| 'deck-card' => [ | ||
| 'type' => 'deck-card', | ||
| 'id' => $cardId, | ||
| 'name' => $params[0], | ||
| 'boardname' => $params[1], | ||
| 'stackname' => $stack->getTitle(), | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', | ||
| ], | ||
| 'deck-board' => [ | ||
| 'type' => 'deck-board', | ||
| 'id' => $boardId, | ||
| 'name' => $params[1], | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, | ||
| ], | ||
| ] | ||
| ); | ||
| $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); | ||
| break; | ||
| case 'card-comment-mentioned': | ||
|
|
@@ -138,6 +186,11 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| if (!$boardId) { | ||
| throw new AlreadyProcessedException(); | ||
| } | ||
|
|
||
| $card = $this->cardMapper->find($cardId); | ||
| $stackId = $card->getStackId(); | ||
| $stack = $this->stackMapper->find($stackId); | ||
|
|
||
| $initiator = $this->userManager->get($params[2]); | ||
| if ($initiator !== null) { | ||
| $dn = $initiator->getDisplayName(); | ||
|
|
@@ -148,8 +201,16 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| (string) $l->t('%s has mentioned you in a comment on "%s".', [$dn, $params[0]]) | ||
| ); | ||
| $notification->setRichSubject( | ||
| (string) $l->t('{user} has mentioned you in a comment on "%s".', [$params[0]]), | ||
| $l->t('{user} has mentioned you in a comment on {deck-card}.'), | ||
| [ | ||
| 'deck-card' => [ | ||
| 'type' => 'deck-card', | ||
| 'id' => $cardId, | ||
| 'name' => $params[0], | ||
| 'boardname' => $params[1], | ||
| 'stackname' => $stack->getTitle(), | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', | ||
| ], | ||
| 'user' => [ | ||
| 'type' => 'user', | ||
| 'id' => $params[2], | ||
|
|
@@ -177,8 +238,14 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| (string) $l->t('The board "%s" has been shared with you by %s.', [$params[0], $dn]) | ||
| ); | ||
| $notification->setRichSubject( | ||
| (string) $l->t('{user} has shared the board %s with you.', [$params[0]]), | ||
| $l->t('{user} has shared {deck-board} with you.'), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if we should keep "… the board …"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No strong opinions here, but I'd say the icon is already enough to indicate that it is deck related. Maybe @jancborchardt can comment about the general wording. |
||
| [ | ||
| 'deck-board' => [ | ||
| 'type' => 'deck-board', | ||
| 'id' => $boardId, | ||
| 'name' => $params[0], | ||
| 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, | ||
| ], | ||
| 'user' => [ | ||
| 'type' => 'user', | ||
| 'id' => $params[1], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a shorter way for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not as of right now as we always use an entity and don't have any way to map joined results to it currently. I'd say we keep it like this and if we encounter more places where this would be useful we can add a helper to do this in one query.