Skip to content

Commit

Permalink
Implement the notifications app as IDeferrableApp
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 4, 2020
1 parent f6bc58c commit 101c4bf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@


use OCA\Notifications\Exceptions\NotificationNotFoundException;
use OCP\Notification\IApp;
use OCP\Notification\IDeferrableApp;
use OCP\Notification\INotification;
use Symfony\Component\Console\Output\OutputInterface;

class App implements IApp {
class App implements IDeferrableApp {
/** @var Handler */
protected $handler;
/** @var Push */
Expand All @@ -50,14 +50,12 @@ public function setOutput(OutputInterface $output): void {
public function notify(INotification $notification): void {
$notificationId = $this->handler->add($notification);

$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');
}
$this->push->flushPayloads();
}

/**
Expand All @@ -76,12 +74,18 @@ public function getCount(INotification $notification): int {
public function markProcessed(INotification $notification): void {
$deleted = $this->handler->delete($notification);

$this->push->deferPayloads();
foreach ($deleted as $user => $notifications) {
foreach ($notifications as $notificationId) {
$this->push->pushDeleteToDevice($user, $notificationId);
}
}
}

public function defer(): void {
$this->push->deferPayloads();
}

public function flush(): void {
$this->push->flushPayloads();
}
}

0 comments on commit 101c4bf

Please sign in to comment.