Skip to content

Commit

Permalink
Merge pull request #3744 from nextcloud/bugfix/noid/backportable-defe…
Browse files Browse the repository at this point in the history
…rable-notification-workaround

Dispatch an event to signal interest in defering the notifications
  • Loading branch information
nickvergessen authored Jun 8, 2020
2 parents 7b3b93a + a3c2adf commit e102fe5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Notification\IApp;
use OCP\Notification\IManager;
use OCP\ILogger;
use OCP\IUser;
Expand All @@ -38,6 +40,8 @@ class Listener {

/** @var IManager */
protected $notificationManager;
/** @var IEventDispatcher */
protected $dispatcher;
/** @var IUserSession */
protected $userSession;
/** @var ITimeFactory */
Expand All @@ -49,10 +53,12 @@ class Listener {
protected $shouldSendCallNotification = false;

public function __construct(IManager $notificationManager,
IEventDispatcher $dispatcher,
IUserSession $userSession,
ITimeFactory $timeFactory,
ILogger $logger) {
$this->notificationManager = $notificationManager;
$this->dispatcher = $dispatcher;
$this->userSession = $userSession;
$this->timeFactory = $timeFactory;
$this->logger = $logger;
Expand Down Expand Up @@ -200,6 +206,7 @@ public function sendCallNotifications(Room $room): void {
$actor = $this->userSession->getUser();
$actorId = $actor instanceof IUser ? $actor->getUID() :'';

$this->dispatcher->dispatch(IApp::class . '::defer', new Event());
$notification = $this->notificationManager->createNotification();
$dateTime = $this->timeFactory->getDateTime();
try {
Expand All @@ -217,6 +224,7 @@ public function sendCallNotifications(Room $room): void {
->setDateTime($dateTime);
} catch (\InvalidArgumentException $e) {
$this->logger->logException($e, ['app' => 'spreed']);
$this->dispatcher->dispatch(IApp::class . '::flush', new Event());
return;
}

Expand All @@ -233,6 +241,7 @@ public function sendCallNotifications(Room $room): void {
$this->logger->logException($e, ['app' => 'spreed']);
}
}
$this->dispatcher->dispatch(IApp::class . '::flush', new Event());
}

/**
Expand Down

0 comments on commit e102fe5

Please sign in to comment.