From e40e9e8ebf5f6b4817a0a4ea21f31cb30166cf02 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Mon, 7 Aug 2023 18:08:39 +0200 Subject: [PATCH] use app name instead of id in notification text Signed-off-by: Julien Veyssier --- lib/Notification/Notifier.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index b1450ef2..158d1c0d 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -4,9 +4,8 @@ use InvalidArgumentException; use OCA\TPAssistant\AppInfo\Application; +use OCP\App\IAppManager; use OCP\IURLGenerator; -use OCP\IUser; -use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\IAction; use OCP\Notification\INotification; @@ -17,8 +16,8 @@ class Notifier implements INotifier { public function __construct( private IFactory $factory, - private IUserManager $userManager, private IURLGenerator $url, + private IAppManager $appManager, private ?string $userId, ) { } @@ -58,10 +57,16 @@ public function prepare(INotification $notification, string $languageCode): INot $l = $this->factory->get(Application::APP_ID, $languageCode); $params = $notification->getSubjectParameters(); + $schedulingAppId = $params['appId']; + $schedulingAppInfo = $this->appManager->getAppInfo($schedulingAppId); + if ($schedulingAppInfo === null) { + throw new InvalidArgumentException(); + } + $schedulingAppName = $schedulingAppInfo['name']; switch ($notification->getSubject()) { case 'success': - $subject = $l->t('Assistant Task for app %1$s has finished', [$params['appId']]); + $subject = $l->t('Assistant Task for %1$s has finished', [$schedulingAppName]); $content = $l->t('The input was: %1$s', [$params['input']]); $link = $params['target'] ?? $this->url->linkToRouteAbsolute(Application::APP_ID . '.assistant.getTaskResultPage', ['taskId' => $params['id']]); $iconUrl = $this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')); @@ -84,7 +89,7 @@ public function prepare(INotification $notification, string $languageCode): INot return $notification; case 'failure': - $subject = $l->t('Assistant Task for app %1$s has failed', [$params['appId']]); + $subject = $l->t('Assistant Task for %1$s has failed', [$schedulingAppName]); $content = $l->t('The input was: %1$s', [$params['input']]); $link = $params['target'] ?? $this->url->linkToRouteAbsolute(Application::APP_ID . '.assistant.getTaskResultPage', ['taskId' => $params['id']]); $iconUrl = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/error.svg'));