diff options
author | Joas Schilling <coding@schilljs.com> | 2019-07-17 14:07:12 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-07-18 13:23:26 +0300 |
commit | 771bb4ec5364e78f6fb3e3aee5de0a7ad62b6299 (patch) | |
tree | 976f6622cbbc76fd0170cdcbfffe5414814e4e20 /lib/Notification/Notifier.php | |
parent | c3c735e7edfb36e2f16b66c2d9da02a6463a0bf1 (diff) |
Adjust the text of past-notifications and add actions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r-- | lib/Notification/Notifier.php | 104 |
1 files changed, 76 insertions, 28 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 06bd595cb..b238327e2 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -38,6 +38,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\AlreadyProcessedException; +use OCP\Notification\IAction; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; @@ -311,6 +312,7 @@ class Notifier implements INotifier { * @param IL10N $l * @return INotification * @throws \InvalidArgumentException + * @throws AlreadyProcessedException */ protected function parseInvitation(INotification $notification, Room $room, IL10N $l): INotification { if ($notification->getObjectType() !== 'room') { @@ -322,17 +324,20 @@ class Notifier implements INotifier { $user = $this->userManager->get($uid); if (!$user instanceof IUser) { - throw new \InvalidArgumentException('Calling user does not exist anymore'); + throw new AlreadyProcessedException(); } $roomName = $room->getDisplayName($notification->getUser()); if ($room->getType() === Room::ONE_TO_ONE_CALL) { + $subject = $l->t('{user} invited you to a private conversation'); + if ($room->hasSessionsInCall()) { + $notification = $this->addActionButton($notification, $l->t('Join call')); + } + $notification - ->setParsedSubject( - $l->t('%s invited you to a private conversation', [$user->getDisplayName()]) - ) + ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject)) ->setRichSubject( - $l->t('{user} invited you to a private conversation'), [ + $subject, [ 'user' => [ 'type' => 'user', 'id' => $uid, @@ -348,12 +353,15 @@ class Notifier implements INotifier { ); } else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) { + $subject = $l->t('{user} invited you to a group conversation: {call}'); + if ($room->hasSessionsInCall()) { + $notification = $this->addActionButton($notification, $l->t('Join call')); + } + $notification - ->setParsedSubject( - $l->t('%s invited you to a group conversation: %s', [$user->getDisplayName(), $roomName]) - ) + ->setParsedSubject(str_replace(['{user}', '{call}'], [$user->getDisplayName(), $roomName], $subject)) ->setRichSubject( - $l->t('{user} invited you to a group conversation: {call}'), [ + $subject, [ 'user' => [ 'type' => 'user', 'id' => $uid, @@ -368,7 +376,7 @@ class Notifier implements INotifier { ] ); } else { - throw new \InvalidArgumentException('Unknown room type'); + throw new AlreadyProcessedException(); } return $notification; @@ -380,6 +388,7 @@ class Notifier implements INotifier { * @param IL10N $l * @return INotification * @throws \InvalidArgumentException + * @throws AlreadyProcessedException */ protected function parseCall(INotification $notification, Room $room, IL10N $l): INotification { if ($notification->getObjectType() !== 'call') { @@ -392,12 +401,17 @@ class Notifier implements INotifier { $calleeId = $parameters['callee']; $user = $this->userManager->get($calleeId); if ($user instanceof IUser) { + if ($room->hasSessionsInCall()) { + $notification = $this->addActionButton($notification, $l->t('Answer call')); + $subject = $l->t('{user} wants to talk with you'); + } else { + $subject = $l->t('You missed a call from {user}'); + } + $notification - ->setParsedSubject( - str_replace('{user}', $user->getDisplayName(), $l->t('{user} wants to talk with you')) - ) + ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject)) ->setRichSubject( - $l->t('{user} wants to talk with you'), [ + $subject, [ 'user' => [ 'type' => 'user', 'id' => $calleeId, @@ -412,16 +426,21 @@ class Notifier implements INotifier { ] ); } else { - throw new \InvalidArgumentException('Calling user does not exist anymore'); + throw new AlreadyProcessedException(); } } else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) { + if ($room->hasSessionsInCall()) { + $notification = $this->addActionButton($notification, $l->t('Join call')); + $subject = $l->t('A group call has started in {call}'); + } else { + $subject = $l->t('You missed a group call in {call}'); + } + $notification - ->setParsedSubject( - str_replace('{call}', $roomName, $l->t('A group call has started in {call}')) - ) + ->setParsedSubject(str_replace('{call}', $roomName, $subject)) ->setRichSubject( - $l->t('A group call has started in {call}'), [ + $subject, [ 'call' => [ 'type' => 'call', 'id' => $room->getId(), @@ -432,7 +451,7 @@ class Notifier implements INotifier { ); } else { - throw new \InvalidArgumentException('Unknown room type'); + throw new AlreadyProcessedException(); } return $notification; @@ -444,6 +463,7 @@ class Notifier implements INotifier { * @param IL10N $l * @return INotification * @throws \InvalidArgumentException + * @throws AlreadyProcessedException */ protected function parsePasswordRequest(INotification $notification, Room $room, IL10N $l): INotification { if ($notification->getObjectType() !== 'call') { @@ -453,7 +473,7 @@ class Notifier implements INotifier { try { $share = $this->shareManager->getShareByToken($room->getObjectId()); } catch (ShareNotFound $e) { - throw new \InvalidArgumentException('Unknown share'); + throw new AlreadyProcessedException(); } try { @@ -463,17 +483,25 @@ class Notifier implements INotifier { 'name' => $share->getNode()->getName(), ]; } catch (\OCP\Files\NotFoundException $e) { - throw new \InvalidArgumentException('Unknown file'); + throw new AlreadyProcessedException(); + } + + $callIsActive = $room->hasSessionsInCall(); + if ($callIsActive) { + $notification = $this->addActionButton($notification, $l->t('Answer call')); } if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) { $sharedWith = $share->getSharedWith(); + if ($callIsActive) { + $subject = $l->t('{email} is requesting the password to access {file}'); + } else { + $subject = $l->t('{email} tried to requested the password to access {file}'); + } $notification - ->setParsedSubject(str_replace(['{email}', '{file}'], [$sharedWith, $file['name']], $l->t('{email} requested the password to access {file}'))) - ->setRichSubject( - $l->t('{email} requested the password to access {file}'), - [ + ->setParsedSubject(str_replace(['{email}', '{file}'], [$sharedWith, $file['name']], $subject)) + ->setRichSubject($subject, [ 'email' => [ 'type' => 'email', 'id' => $sharedWith, @@ -483,11 +511,31 @@ class Notifier implements INotifier { ] ); } else { + if ($callIsActive) { + $subject = $l->t('Someone is requesting the password to access {file}'); + } else { + $subject = $l->t('Someone tried to requested the password to access {file}'); + } + $notification - ->setParsedSubject(str_replace('{file}', $file['name'], $l->t('Someone requested the password to access {file}'))) - ->setRichSubject($l->t('Someone requested the password to access {file}'), ['file' => $file]); + ->setParsedSubject(str_replace('{file}', $file['name'], $subject)) + ->setRichSubject($subject, ['file' => $file]); } + $notification = $this->addActionButton($notification, $l->t('Answer call')); + + return $notification; + } + + protected function addActionButton(INotification $notification, string $label): INotification { + $action = $notification->createAction(); + $action->setLabel($label) + ->setParsedLabel($label) + ->setLink($notification->getLink(), IAction::TYPE_WEB) + ->setPrimary(true); + + $notification->addParsedAction($action); + return $notification; } } |