diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 6a2402930..1b1dd4bb6 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -97,6 +97,8 @@ public function listNotifications(string $apiVersion): DataResponse { ); } + $this->manager->preloadDataForParsing($notifications, $language); + $data = []; $notificationIds = []; foreach ($notifications as $notificationId => $notification) { @@ -155,6 +157,8 @@ public function getNotification(string $apiVersion, int $id): DataResponse { $user = $this->session->getUser(); $language = $this->l10nFactory->getUserLanguage($user); + $this->manager->preloadDataForParsing([$notification], $language); + try { $notification = $this->manager->prepare($notification, $language); } catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException) { diff --git a/lib/MailNotifications.php b/lib/MailNotifications.php index 610c47c31..7e01b61f2 100644 --- a/lib/MailNotifications.php +++ b/lib/MailNotifications.php @@ -131,6 +131,8 @@ protected function sendEmailToUser(Settings $settings, array $notifications, str $lastSendId = array_key_first($notifications); $lastSendTime = $this->timeFactory->getTime(); + $this->manager->preloadDataForParsing($notifications, $language); + $preparedNotifications = []; foreach ($notifications as $notification) { /** @var INotification $preparedNotification */ diff --git a/lib/Push.php b/lib/Push.php index 582c91a4f..61ffe7389 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -246,8 +246,10 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf $language = $this->l10nFactory->getUserLanguage($user); $this->printInfo('Language is set to ' . $language); + $this->notificationManager->setPreparingPushNotification(true); + $this->notificationManager->preloadDataForParsing([$notification], $language); + try { - $this->notificationManager->setPreparingPushNotification(true); $notification = $this->notificationManager->prepare($notification, $language); } catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException $e) { // FIXME remove \InvalidArgumentException in Nextcloud 39 diff --git a/tests/Unit/Controller/EndpointControllerTest.php b/tests/Unit/Controller/EndpointControllerTest.php index 24897edd1..b96e12dfb 100644 --- a/tests/Unit/Controller/EndpointControllerTest.php +++ b/tests/Unit/Controller/EndpointControllerTest.php @@ -151,6 +151,9 @@ public function testListNotifications(string $apiVersion, array $notifications, $this->manager->expects($this->once()) ->method('createNotification') ->willReturn($filter); + $this->manager->expects(self::once()) + ->method('preloadDataForParsing') + ->with($notifications, 'en'); $this->manager->expects($this->exactly(\count($notifications))) ->method('prepare') ->willReturnArgument(0); @@ -220,6 +223,10 @@ public function testListNotificationsThrows(string $apiVersion, array $notificat $this->manager->expects($this->once()) ->method('flush'); + $this->manager->expects(self::once()) + ->method('preloadDataForParsing') + ->with($notifications, 'en'); + $throw = true; $this->manager->expects($this->exactly(2)) ->method('prepare') @@ -294,6 +301,9 @@ public function testGetNotification(string $apiVersion, int $id, string $usernam $this->manager->expects($this->once()) ->method('hasNotifiers') ->willReturn(true); + $this->manager->expects(self::once()) + ->method('preloadDataForParsing') + ->with([$notification], 'en'); $this->manager->expects($this->once()) ->method('prepare') ->with($notification) @@ -341,11 +351,16 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, ->method('hasNotifiers') ->willReturn($hasNotifiers); + if ($notification instanceof NotificationNotFoundException) { $this->handler->expects($called ? $this->once() : $this->never()) ->method('getById') ->willThrowException($notification); + $this->manager->expects(self::never()) + ->method('preloadDataForParsing') + ->with([$notification], 'en'); + $this->manager->expects($called && !$notification instanceof NotificationNotFoundException ? $this->once() : $this->never()) ->method('prepare') ->willThrowException(new \InvalidArgumentException()); @@ -359,6 +374,10 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, ->with($this->user) ->willReturn('en'); + $this->manager->expects(self::once()) + ->method('preloadDataForParsing') + ->with([$notification], 'en'); + $this->manager->expects($this->once()) ->method('prepare') ->willThrowException(new \InvalidArgumentException());