Skip to content

Commit f95ce30

Browse files
committed
feat: indicate reason for preloading notifications
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 6d5dd4b commit f95ce30

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@
701701
'OCP\\Notification\\IncompleteNotificationException' => $baseDir . '/lib/public/Notification/IncompleteNotificationException.php',
702702
'OCP\\Notification\\IncompleteParsedNotificationException' => $baseDir . '/lib/public/Notification/IncompleteParsedNotificationException.php',
703703
'OCP\\Notification\\InvalidValueException' => $baseDir . '/lib/public/Notification/InvalidValueException.php',
704+
'OCP\\Notification\\NotificationPreloadReason' => $baseDir . '/lib/public/Notification/NotificationPreloadReason.php',
704705
'OCP\\Notification\\UnknownNotificationException' => $baseDir . '/lib/public/Notification/UnknownNotificationException.php',
705706
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
706707
'OCP\\OCM\\Exceptions\\OCMArgumentException' => $baseDir . '/lib/public/OCM/Exceptions/OCMArgumentException.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
742742
'OCP\\Notification\\IncompleteNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteNotificationException.php',
743743
'OCP\\Notification\\IncompleteParsedNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteParsedNotificationException.php',
744744
'OCP\\Notification\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Notification/InvalidValueException.php',
745+
'OCP\\Notification\\NotificationPreloadReason' => __DIR__ . '/../../..' . '/lib/public/Notification/NotificationPreloadReason.php',
745746
'OCP\\Notification\\UnknownNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/UnknownNotificationException.php',
746747
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
747748
'OCP\\OCM\\Exceptions\\OCMArgumentException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMArgumentException.php',

lib/private/Notification/Manager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCP\Notification\INotification;
2323
use OCP\Notification\INotifier;
2424
use OCP\Notification\IPreloadableNotifier;
25+
use OCP\Notification\NotificationPreloadReason;
2526
use OCP\Notification\UnknownNotificationException;
2627
use OCP\RichObjectStrings\IRichTextFormatter;
2728
use OCP\RichObjectStrings\IValidator;
@@ -391,14 +392,18 @@ public function prepare(INotification $notification, string $languageCode): INot
391392
return $notification;
392393
}
393394

394-
public function preloadDataForParsing(array $notifications, string $languageCode): void {
395+
public function preloadDataForParsing(
396+
array $notifications,
397+
string $languageCode,
398+
NotificationPreloadReason $reason,
399+
): void {
395400
$notifiers = $this->getNotifiers();
396401
foreach ($notifiers as $notifier) {
397402
if (!($notifier instanceof IPreloadableNotifier)) {
398403
continue;
399404
}
400405

401-
$notifier->preloadDataForParsing($notifications, $languageCode);
406+
$notifier->preloadDataForParsing($notifications, $languageCode, $reason);
402407
}
403408
}
404409

lib/public/Notification/IPreloadableNotifier.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ interface IPreloadableNotifier extends INotifier {
2626
*
2727
* @param INotification[] $notifications The notifications which are about to be prepared in the next step.
2828
* @param string $languageCode The code of the language that should be used to prepare the notification.
29+
* @param NotificationPreloadReason $reason The reason for preloading the given notifications to facilitate smarter decisions about what data to preload.
2930
*/
30-
public function preloadDataForParsing(array $notifications, string $languageCode): void;
31+
public function preloadDataForParsing(
32+
array $notifications,
33+
string $languageCode,
34+
NotificationPreloadReason $reason,
35+
): void;
3136
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\Notification;
11+
12+
use OCP\AppFramework\Attribute\Consumable;
13+
14+
/**
15+
* Indicates the reason for preloading notifications to facilitate smarter decisions about what data
16+
* to preload.
17+
*/
18+
#[Consumable(since: '32.0.0')]
19+
enum NotificationPreloadReason {
20+
/**
21+
* Preparing a single notification for many users.
22+
*
23+
* @since 32.0.0
24+
*/
25+
case Push;
26+
27+
/**
28+
* Preparing many notifications for many users.
29+
*
30+
* @since 32.0.0
31+
*/
32+
case Email;
33+
34+
/**
35+
* Preparing many notifications for a single user.
36+
*
37+
* @since 32.0.0
38+
*/
39+
case EndpointController;
40+
}

0 commit comments

Comments
 (0)