From fd6869c35c6844aa55aaccc07240d08b381d28da Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Mon, 4 Aug 2025 09:15:05 +0200 Subject: [PATCH 1/4] feat: make use of IPreloadableNotifier Signed-off-by: Richard Steinmetz --- lib/Controller/EndpointController.php | 4 ++++ lib/MailNotifications.php | 2 ++ lib/Push.php | 2 ++ tests/Unit/Controller/EndpointControllerTest.php | 14 ++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 6a2402930..22ac76d86 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -97,6 +97,8 @@ public function listNotifications(string $apiVersion): DataResponse { ); } + $this->manager->preloadMany($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->preloadMany([$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..02ff8d69d 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->preloadMany($notifications, $language); + $preparedNotifications = []; foreach ($notifications as $notification) { /** @var INotification $preparedNotification */ diff --git a/lib/Push.php b/lib/Push.php index 582c91a4f..0a60419ad 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -246,6 +246,8 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf $language = $this->l10nFactory->getUserLanguage($user); $this->printInfo('Language is set to ' . $language); + $this->notificationManager->preloadMany([$notification], $language); + try { $this->notificationManager->setPreparingPushNotification(true); $notification = $this->notificationManager->prepare($notification, $language); diff --git a/tests/Unit/Controller/EndpointControllerTest.php b/tests/Unit/Controller/EndpointControllerTest.php index 24897edd1..a1dfedd0d 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('preloadMany') + ->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('preloadMany') + ->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('preloadMany') + ->with([$notification], 'en'); $this->manager->expects($this->once()) ->method('prepare') ->with($notification) @@ -341,6 +351,10 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, ->method('hasNotifiers') ->willReturn($hasNotifiers); + $this->manager->expects(self::once()) + ->method('preloadMany') + ->with([$notification], 'en'); + if ($notification instanceof NotificationNotFoundException) { $this->handler->expects($called ? $this->once() : $this->never()) ->method('getById') From f33beac39ff3d684cf55d69f61c0cedbdb088bff Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 5 Aug 2025 15:39:39 +0200 Subject: [PATCH 2/4] fixup! feat: make use of IPreloadableNotifier --- lib/Controller/EndpointController.php | 4 ++-- lib/MailNotifications.php | 2 +- lib/Push.php | 2 +- tests/Unit/Controller/EndpointControllerTest.php | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 22ac76d86..1b1dd4bb6 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -97,7 +97,7 @@ public function listNotifications(string $apiVersion): DataResponse { ); } - $this->manager->preloadMany($notifications, $language); + $this->manager->preloadDataForParsing($notifications, $language); $data = []; $notificationIds = []; @@ -157,7 +157,7 @@ public function getNotification(string $apiVersion, int $id): DataResponse { $user = $this->session->getUser(); $language = $this->l10nFactory->getUserLanguage($user); - $this->manager->preloadMany([$notification], $language); + $this->manager->preloadDataForParsing([$notification], $language); try { $notification = $this->manager->prepare($notification, $language); diff --git a/lib/MailNotifications.php b/lib/MailNotifications.php index 02ff8d69d..7e01b61f2 100644 --- a/lib/MailNotifications.php +++ b/lib/MailNotifications.php @@ -131,7 +131,7 @@ protected function sendEmailToUser(Settings $settings, array $notifications, str $lastSendId = array_key_first($notifications); $lastSendTime = $this->timeFactory->getTime(); - $this->manager->preloadMany($notifications, $language); + $this->manager->preloadDataForParsing($notifications, $language); $preparedNotifications = []; foreach ($notifications as $notification) { diff --git a/lib/Push.php b/lib/Push.php index 0a60419ad..2f36da2ca 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -246,7 +246,7 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf $language = $this->l10nFactory->getUserLanguage($user); $this->printInfo('Language is set to ' . $language); - $this->notificationManager->preloadMany([$notification], $language); + $this->notificationManager->preloadDataForParsing([$notification], $language); try { $this->notificationManager->setPreparingPushNotification(true); diff --git a/tests/Unit/Controller/EndpointControllerTest.php b/tests/Unit/Controller/EndpointControllerTest.php index a1dfedd0d..bdfa2aadf 100644 --- a/tests/Unit/Controller/EndpointControllerTest.php +++ b/tests/Unit/Controller/EndpointControllerTest.php @@ -152,7 +152,7 @@ public function testListNotifications(string $apiVersion, array $notifications, ->method('createNotification') ->willReturn($filter); $this->manager->expects(self::once()) - ->method('preloadMany') + ->method('preloadDataForParsing') ->with($notifications, 'en'); $this->manager->expects($this->exactly(\count($notifications))) ->method('prepare') @@ -224,7 +224,7 @@ public function testListNotificationsThrows(string $apiVersion, array $notificat ->method('flush'); $this->manager->expects(self::once()) - ->method('preloadMany') + ->method('preloadDataForParsing') ->with($notifications, 'en'); $throw = true; @@ -302,7 +302,7 @@ public function testGetNotification(string $apiVersion, int $id, string $usernam ->method('hasNotifiers') ->willReturn(true); $this->manager->expects(self::once()) - ->method('preloadMany') + ->method('preloadDataForParsing') ->with([$notification], 'en'); $this->manager->expects($this->once()) ->method('prepare') @@ -352,7 +352,7 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, ->willReturn($hasNotifiers); $this->manager->expects(self::once()) - ->method('preloadMany') + ->method('preloadDataForParsing') ->with([$notification], 'en'); if ($notification instanceof NotificationNotFoundException) { From a590e2b1497ad665ea3174c27f0e0abab828abc8 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 6 Aug 2025 11:23:05 +0200 Subject: [PATCH 3/4] fixup! feat: make use of IPreloadableNotifier --- tests/Unit/Controller/EndpointControllerTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Controller/EndpointControllerTest.php b/tests/Unit/Controller/EndpointControllerTest.php index bdfa2aadf..b96e12dfb 100644 --- a/tests/Unit/Controller/EndpointControllerTest.php +++ b/tests/Unit/Controller/EndpointControllerTest.php @@ -351,15 +351,16 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, ->method('hasNotifiers') ->willReturn($hasNotifiers); - $this->manager->expects(self::once()) - ->method('preloadDataForParsing') - ->with([$notification], 'en'); 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()); @@ -373,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()); From afa2450fa2d8b9b82d8518ea70b20420c8bb0c6e Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 6 Aug 2025 11:24:28 +0200 Subject: [PATCH 4/4] fixup! feat: make use of IPreloadableNotifier --- lib/Push.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Push.php b/lib/Push.php index 2f36da2ca..61ffe7389 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -246,10 +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