From 79c9c59b760a1681f2555a721e80f604c5ff79ef Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 26 Mar 2024 14:47:36 -0300 Subject: [PATCH] Prevent warning when parse notification Signed-off-by: Vitor Mattos --- lib/Notification/Notifier.php | 77 +++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index a22f354ac9..28abb0dfd9 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -95,46 +95,51 @@ private function parseSignRequest( bool $update ): INotification { $parameters = $notification->getSubjectParameters(); - $notification - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))) - ->setLink($parameters['file']['link']); - $subject = $l->t('{from} requested your signature on {file}'); - $notification->setParsedSubject( - str_replace( - ['{from}', '{file}'], - [ - $parameters['from']['name'], - $parameters['file']['name'], - ], - $subject - )) - ->setRichSubject($subject, $parameters); + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); + if (isset($parameters['file'])) { + $notification->setLink($parameters['file']['link']); + $signAction = $notification->createAction() + ->setParsedLabel($l->t('View')) + ->setPrimary(true) + ->setLink( + $parameters['file']['link'], + IAction::TYPE_WEB + ); + $notification->addParsedAction($signAction); + if (isset($parameters['from'])) { + $subject = $l->t('{from} requested your signature on {file}'); + $notification->setParsedSubject( + str_replace( + ['{from}', '{file}'], + [ + $parameters['from']['name'], + $parameters['file']['name'], + ], + $subject + )) + ->setRichSubject($subject, $parameters); + } + } if ($update) { $notification->setParsedMessage($l->t('Changes have been made in a file that you have to sign.')); } - $signAction = $notification->createAction() - ->setParsedLabel($l->t('View')) - ->setPrimary(true) - ->setLink( - $parameters['file']['link'], - IAction::TYPE_WEB - ); - $notification->addParsedAction($signAction); - $dismissAction = $notification->createAction() - ->setParsedLabel($l->t('Dismiss notification')) - ->setLink( - $this->url->linkToOCSRouteAbsolute( - 'libresign.notify.notificationDismiss', - [ - 'apiVersion' => 'v1', - 'timestamp' => $notification->getDateTime()->getTimestamp(), - 'signRequestId' => $parameters['signRequest']['id'], - ], - ), - IAction::TYPE_DELETE - ); - $notification->addParsedAction($dismissAction); + if (isset($parameters['signRequest'])) { + $dismissAction = $notification->createAction() + ->setParsedLabel($l->t('Dismiss notification')) + ->setLink( + $this->url->linkToOCSRouteAbsolute( + 'libresign.notify.notificationDismiss', + [ + 'apiVersion' => 'v1', + 'timestamp' => $notification->getDateTime()->getTimestamp(), + 'signRequestId' => $parameters['signRequest']['id'], + ], + ), + IAction::TYPE_DELETE + ); + $notification->addParsedAction($dismissAction); + } return $notification; } }