Skip to content

Commit

Permalink
fix(app): Allow to ge thte last inserted notification ID
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 23, 2024
1 parent 47c36a4 commit 87d7ff4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Output\OutputInterface;

class App implements IDeferrableApp {
protected ?int $lastInsertedId = null;
public function __construct(
protected Handler $handler,
protected Push $push,
Expand All @@ -33,15 +34,19 @@ public function setOutput(OutputInterface $output): void {
* @since 8.2.0
*/
public function notify(INotification $notification): void {
$notificationId = $this->handler->add($notification);
$this->lastInsertedId = $this->handler->add($notification);

try {
$this->push->pushToDevice($notificationId, $notification);
$this->push->pushToDevice($this->lastInsertedId, $notification);
} catch (NotificationNotFoundException $e) {
$this->logger->error('Error while preparing push notification', ['exception' => $e]);
}
}

public function getLastInsertedId(): ?int {
return $this->lastInsertedId;
}

/**
* @param INotification $notification
* @return int
Expand Down

0 comments on commit 87d7ff4

Please sign in to comment.