|
@@ -31,6 +31,7 @@ use OCP\AppFramework\QueryException;
|
|
|
use OCP\ILogger;
|
|
|
use OCP\Notification\AlreadyProcessedException;
|
|
|
use OCP\Notification\IApp;
|
|
|
+use OCP\Notification\IDeferrableApp;
|
|
|
use OCP\Notification\IDismissableNotifier;
|
|
|
use OCP\Notification\IManager;
|
|
|
use OCP\Notification\INotification;
|
|
@@ -55,6 +56,8 @@ class Manager implements IManager {
|
|
|
|
|
|
/** @var bool */
|
|
|
protected $preparingPushNotification;
|
|
|
+ /** @var bool */
|
|
|
+ protected $deferPushing;
|
|
|
|
|
|
public function __construct(IValidator $validator,
|
|
|
ILogger $logger) {
|
|
@@ -65,6 +68,7 @@ class Manager implements IManager {
|
|
|
$this->appClasses = [];
|
|
|
$this->notifierClasses = [];
|
|
|
$this->preparingPushNotification = false;
|
|
|
+ $this->deferPushing = false;
|
|
|
}
|
|
|
/**
|
|
|
* @param string $appClass The service must implement IApp, otherwise a
|
|
@@ -199,6 +203,46 @@ class Manager implements IManager {
|
|
|
return $this->preparingPushNotification;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The calling app should only "flush" when it got returned true on the defer call
|
|
|
+ * @return bool
|
|
|
+ * @since 20.0.0
|
|
|
+ */
|
|
|
+ public function defer(): bool {
|
|
|
+ $alreadyDeferring = $this->deferPushing;
|
|
|
+ $this->deferPushing = true;
|
|
|
+
|
|
|
+ $apps = $this->getApps();
|
|
|
+
|
|
|
+ foreach ($apps as $app) {
|
|
|
+ if ($app instanceof IDeferrableApp) {
|
|
|
+ $app->defer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return !$alreadyDeferring;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @since 20.0.0
|
|
|
+ */
|
|
|
+ public function flush(): void {
|
|
|
+ $apps = $this->getApps();
|
|
|
+
|
|
|
+ foreach ($apps as $app) {
|
|
|
+ if (!$app instanceof IDeferrableApp) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $app->flush();
|
|
|
+ } catch (\InvalidArgumentException $e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->deferPushing = false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param INotification $notification
|
|
|
* @throws \InvalidArgumentException When the notification is not valid
|