Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Controller/EndpointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
);
}

$this->manager->preloadMany($notifications, $language);

Check failure on line 100 in lib/Controller/EndpointController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Controller/EndpointController.php:100:19: UndefinedInterfaceMethod: Method OCP\Notification\IManager::preloadMany does not exist (see https://psalm.dev/181)

$data = [];
$notificationIds = [];
foreach ($notifications as $notificationId => $notification) {
Expand Down Expand Up @@ -155,6 +157,8 @@
$user = $this->session->getUser();
$language = $this->l10nFactory->getUserLanguage($user);

$this->manager->preloadMany([$notification], $language);

Check failure on line 160 in lib/Controller/EndpointController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Controller/EndpointController.php:160:19: UndefinedInterfaceMethod: Method OCP\Notification\IManager::preloadMany does not exist (see https://psalm.dev/181)

try {
$notification = $this->manager->prepare($notification, $language);
} catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException) {
Expand Down
2 changes: 2 additions & 0 deletions lib/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
$lastSendId = array_key_first($notifications);
$lastSendTime = $this->timeFactory->getTime();

$this->manager->preloadMany($notifications, $language);

Check failure on line 134 in lib/MailNotifications.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/MailNotifications.php:134:19: UndefinedInterfaceMethod: Method OCP\Notification\IManager::preloadMany does not exist (see https://psalm.dev/181)

$preparedNotifications = [];
foreach ($notifications as $notification) {
/** @var INotification $preparedNotification */
Expand Down
2 changes: 2 additions & 0 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@
$language = $this->l10nFactory->getUserLanguage($user);
$this->printInfo('Language is set to ' . $language);

$this->notificationManager->preloadMany([$notification], $language);

Check failure on line 249 in lib/Push.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Push.php:249:32: UndefinedInterfaceMethod: Method OCP\Notification\IManager::preloadMany does not exist (see https://psalm.dev/181)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During pushing it sounds a bit weird, but there apps can parse the notification already before sending it. And that should be done, at least grouped by language, so we don't do the same preparsing multiple times.
We do that in Talk already since some time. Documentation is pending and will be done as perparation for my Lightning Talk that I submitted for the Conf.

In case of a push also the information should be there already as the app just created the notification object with the details 🙈

But I guess structurally it makes sense to always have the same calling order.

Copy link
Member Author

@st3iny st3iny Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, because I was thinking about consistency. Can implementations/apps expect that the method is always called? Otherwise, they would have to implement the data fetching logic twice, once in preloadMany and once in prepare.


try {
$this->notificationManager->setPreparingPushNotification(true);
$notification = $this->notificationManager->prepare($notification, $language);
Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/Controller/EndpointControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
Loading