Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions lib/Controller/EndpointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Notification\IManager;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Notification\NotificationPreloadReason;
use OCP\UserStatus\IManager as IUserStatusManager;
use OCP\UserStatus\IUserStatus;

Expand Down Expand Up @@ -97,6 +98,8 @@ public function listNotifications(string $apiVersion): DataResponse {
);
}

$this->manager->preloadDataForParsing($notifications, $language, NotificationPreloadReason::EndpointController);

$data = [];
$notificationIds = [];
foreach ($notifications as $notificationId => $notification) {
Expand Down Expand Up @@ -155,6 +158,8 @@ public function getNotification(string $apiVersion, int $id): DataResponse {
$user = $this->session->getUser();
$language = $this->l10nFactory->getUserLanguage($user);

$this->manager->preloadDataForParsing([$notification], $language, NotificationPreloadReason::EndpointController);

try {
$notification = $this->manager->prepare($notification, $language);
} catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException) {
Expand Down
3 changes: 3 additions & 0 deletions lib/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Notification\IManager;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Notification\NotificationPreloadReason;
use OCP\Util;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -142,6 +143,8 @@ protected function sendEmailToUser(Settings $settings, array $notifications, str
$lastSendId = array_key_first($notifications);
$lastSendTime = $this->timeFactory->getTime();

$this->manager->preloadDataForParsing($notifications, $language, NotificationPreloadReason::Email);

$preparedNotifications = [];
foreach ($notifications as $notification) {
/** @var INotification $preparedNotification */
Expand Down
5 changes: 4 additions & 1 deletion lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Notification\NotificationPreloadReason;
use OCP\Security\ISecureRandom;
use OCP\UserStatus\IManager as IUserStatusManager;
use OCP\UserStatus\IUserStatus;
Expand Down Expand Up @@ -361,8 +362,10 @@ public function pushToDevice(int $id, INotification $notification): void {
$language = $this->l10nFactory->getUserLanguage($user);
$this->printInfo('Language is set to ' . $language);

$this->notificationManager->setPreparingPushNotification(true);
$this->notificationManager->preloadDataForParsing([$notification], $language, NotificationPreloadReason::Push);

try {
$this->notificationManager->setPreparingPushNotification(true);
$notification = $this->notificationManager->prepare($notification, $language);
} catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException $e) {
// FIXME remove \InvalidArgumentException in Nextcloud 39
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Controller/EndpointControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,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 @@ -216,6 +219,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 @@ -285,6 +292,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 @@ -335,6 +345,10 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers,
->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());
Expand All @@ -348,6 +362,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());
Expand Down
Loading