aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Notification/Manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Notification/Manager.php')
-rw-r--r--lib/private/Notification/Manager.php46
1 files changed, 35 insertions, 11 deletions
diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php
index 7d042e6f8d8..0cbda651a8b 100644
--- a/lib/private/Notification/Manager.php
+++ b/lib/private/Notification/Manager.php
@@ -21,7 +21,9 @@ use OCP\Notification\IncompleteNotificationException;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
+use OCP\Notification\IPreloadableNotifier;
use OCP\Notification\UnknownNotificationException;
+use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use OCP\Support\Subscription\IRegistry;
use Psr\Container\ContainerExceptionInterface;
@@ -55,6 +57,7 @@ class Manager implements IManager {
protected IRegistry $subscription,
protected LoggerInterface $logger,
private Coordinator $coordinator,
+ private IRichTextFormatter $richTextFormatter,
) {
$this->cache = $cacheFactory->createDistributed('notifications');
@@ -68,18 +71,26 @@ class Manager implements IManager {
}
/**
* @param string $appClass The service must implement IApp, otherwise a
- * \InvalidArgumentException is thrown later
+ * \InvalidArgumentException is thrown later
* @since 17.0.0
*/
public function registerApp(string $appClass): void {
- $this->appClasses[] = $appClass;
+ // other apps may want to rely on the 'main' notification app so make it deterministic that
+ // the 'main' notification app adds it's notifications first and removes it's notifications last
+ if ($appClass === \OCA\Notifications\App::class) {
+ // add 'main' notifications app to start of internal list of apps
+ array_unshift($this->appClasses, $appClass);
+ } else {
+ // add app to end of internal list of apps
+ $this->appClasses[] = $appClass;
+ }
}
/**
* @param \Closure $service The service must implement INotifier, otherwise a
* \InvalidArgumentException is thrown later
- * @param \Closure $info An array with the keys 'id' and 'name' containing
- * the app id and the app name
+ * @param \Closure $info An array with the keys 'id' and 'name' containing
+ * the app id and the app name
* @deprecated 17.0.0 use registerNotifierService instead.
* @since 8.2.0 - Parameter $info was added in 9.0.0
*/
@@ -93,7 +104,7 @@ class Manager implements IManager {
/**
* @param string $notifierService The service must implement INotifier, otherwise a
- * \InvalidArgumentException is thrown later
+ * \InvalidArgumentException is thrown later
* @since 17.0.0
*/
public function registerNotifierService(string $notifierService): void {
@@ -199,7 +210,7 @@ class Manager implements IManager {
* @since 8.2.0
*/
public function createNotification(): INotification {
- return new Notification($this->validator);
+ return new Notification($this->validator, $this->richTextFormatter);
}
/**
@@ -207,7 +218,9 @@ class Manager implements IManager {
* @since 8.2.0
*/
public function hasNotifiers(): bool {
- return !empty($this->notifiers) || !empty($this->notifierClasses);
+ return !empty($this->notifiers)
+ || !empty($this->notifierClasses)
+ || (!$this->parsedRegistrationContext && !empty($this->coordinator->getRegistrationContext()->getNotifierServices()));
}
/**
@@ -235,7 +248,7 @@ class Manager implements IManager {
$alreadyDeferring = $this->deferPushing;
$this->deferPushing = true;
- $apps = $this->getApps();
+ $apps = array_reverse($this->getApps());
foreach ($apps as $app) {
if ($app instanceof IDeferrableApp) {
@@ -250,7 +263,7 @@ class Manager implements IManager {
* @since 20.0.0
*/
public function flush(): void {
- $apps = $this->getApps();
+ $apps = array_reverse($this->getApps());
foreach ($apps as $app) {
if (!$app instanceof IDeferrableApp) {
@@ -378,11 +391,22 @@ class Manager implements IManager {
return $notification;
}
+ public function preloadDataForParsing(array $notifications, string $languageCode): void {
+ $notifiers = $this->getNotifiers();
+ foreach ($notifiers as $notifier) {
+ if (!($notifier instanceof IPreloadableNotifier)) {
+ continue;
+ }
+
+ $notifier->preloadDataForParsing($notifications, $languageCode);
+ }
+ }
+
/**
* @param INotification $notification
*/
public function markProcessed(INotification $notification): void {
- $apps = $this->getApps();
+ $apps = array_reverse($this->getApps());
foreach ($apps as $app) {
$app->markProcessed($notification);
@@ -394,7 +418,7 @@ class Manager implements IManager {
* @return int
*/
public function getCount(INotification $notification): int {
- $apps = $this->getApps();
+ $apps = array_reverse($this->getApps());
$count = 0;
foreach ($apps as $app) {