Skip to content
Prev Previous commit
Next Next commit
fix(app): Allow to ge thte last inserted notification ID
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and come-nc committed Aug 5, 2024
commit 650b703895919eec9852d3a3812000792b62d489
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