Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
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->preloadDataForParsing($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::preloadDataForParsing 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->preloadDataForParsing([$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::preloadDataForParsing 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->preloadDataForParsing($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::preloadDataForParsing 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->preloadDataForParsing([$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::preloadDataForParsing 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.

Tried moving Talk to IPreloadableNotifier I noticed this should be inside the $this->notificationManager->setPreparingPushNotification(true); wrapping, so apps can optimize the push case better.

In most such cases should be loaded/aware already anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Or should we even add a "preload reason" argument or something?

Because:

  • when pushing we will prepare the same notification for a set of different users (N:1)
  • when preparing emails we will face different users with different items (N:M)
  • and on endpoint controller we are preparing for a single user but different subjects (1:M)

Depending on the case it can can make sense to load data from different directions?


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('preloadDataForParsing')
->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('preloadDataForParsing')
->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('preloadDataForParsing')
->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('preloadDataForParsing')
->with([$notification], 'en');

if ($notification instanceof NotificationNotFoundException) {
$this->handler->expects($called ? $this->once() : $this->never())
->method('getById')
Expand Down
Loading