From 2d2cbf04954a0821b7a2fc87a5010a1adefa6b2e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 4 Jun 2020 15:46:47 +0200 Subject: [PATCH 1/2] Dispatch an event to signal interest in defering the notifications Signed-off-by: Joas Schilling --- lib/Notification/Listener.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index 765a35f3c0e..51c270279f5 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -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; @@ -38,6 +41,8 @@ class Listener { /** @var IManager */ protected $notificationManager; + /** @var IEventDispatcher */ + protected $dispatcher; /** @var IUserSession */ protected $userSession; /** @var ITimeFactory */ @@ -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; @@ -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 { @@ -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; } @@ -233,6 +242,7 @@ public function sendCallNotifications(Room $room): void { $this->logger->logException($e, ['app' => 'spreed']); } } + $this->dispatcher->dispatch(IApp::class . '::flush', new Event()); } /** From a3c2adfbacac0f5a73a92cf4172f48a8ce2bc5e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Jun 2020 09:11:58 +0200 Subject: [PATCH 2/2] PHP CS fixing Signed-off-by: Joas Schilling --- lib/Notification/Listener.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index 51c270279f5..ec832633dc5 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -29,7 +29,6 @@ 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;