Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Dispatch an event to signal interest in defering the notifications
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jun 4, 2020
commit 2d2cbf04954a0821b7a2fc87a5010a1adefa6b2e
10 changes: 10 additions & 0 deletions lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Notification\IApp;
use OCP\Notification\IManager;
use OCP\ILogger;
use OCP\IUser;
Expand All @@ -38,6 +41,8 @@ class Listener {

/** @var IManager */
protected $notificationManager;
/** @var IEventDispatcher */
protected $dispatcher;
/** @var IUserSession */
protected $userSession;
/** @var ITimeFactory */
Expand All @@ -49,10 +54,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 +207,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 +225,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 +242,7 @@ public function sendCallNotifications(Room $room): void {
$this->logger->logException($e, ['app' => 'spreed']);
}
}
$this->dispatcher->dispatch(IApp::class . '::flush', new Event());
}

/**
Expand Down