diff options
Diffstat (limited to 'lib/App.php')
-rw-r--r-- | lib/App.php | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/App.php b/lib/App.php index 4744bba..248255f 100644 --- a/lib/App.php +++ b/lib/App.php @@ -50,12 +50,17 @@ class App implements IApp { public function notify(INotification $notification): void { $notificationId = $this->handler->add($notification); + $shouldFlush = $this->push->deferPayloads(); try { $notificationToPush = $this->handler->getById($notificationId, $notification->getUser()); $this->push->pushToDevice($notificationId, $notificationToPush); } catch (NotificationNotFoundException $e) { throw new \InvalidArgumentException('Error while preparing push notification'); } + + if ($shouldFlush) { + $this->push->flushPayloads(); + } } /** @@ -74,10 +79,23 @@ class App implements IApp { public function markProcessed(INotification $notification): void { $deleted = $this->handler->delete($notification); + $shouldFlush = $this->push->deferPayloads(); foreach ($deleted as $user => $notifications) { foreach ($notifications as $notificationId) { $this->push->pushDeleteToDevice($user, $notificationId); } } + + if ($shouldFlush) { + $this->push->flushPayloads(); + } + } + + public function defer(): void { + $this->push->deferPayloads(); + } + + public function flush(): void { + $this->push->flushPayloads(); } } |