Skip to content

Commit

Permalink
use app name instead of id in notification text
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Aug 7, 2023
1 parent 090b4c5 commit e40e9e8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
}
Expand Down Expand Up @@ -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'));
Expand All @@ -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'));
Expand Down

0 comments on commit e40e9e8

Please sign in to comment.