diff options
author | Joas Schilling <coding@schilljs.com> | 2020-02-11 18:48:42 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-02-11 18:48:42 +0300 |
commit | 9a491f9b00d6569c6404b468046911de3a6ddc12 (patch) | |
tree | 752111cbabfa7214df4d231d97b1358a6da4ca50 /lib/Notification | |
parent | dda45ca138b8420a38b56e2e19f478194ba75d69 (diff) |
Send the notifications after joining the call
This prevents issues when sending takes long, e.g. with a lot of users
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification')
-rw-r--r-- | lib/Notification/Listener.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index cb2a56cf7..9f1a38e29 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -44,6 +44,9 @@ class Listener { /** @var ILogger */ protected $logger; + /** @var bool */ + protected $shouldSendCallNotification = false; + public function __construct(IManager $notificationManager, IUserSession $userSession, ITimeFactory $timeFactory, @@ -78,13 +81,20 @@ class Listener { $listener = static function(RoomEvent $event) { /** @var self $listener */ $listener = \OC::$server->query(self::class); - $listener->generateCallNotifications($event->getRoom()); + $listener->checkCallNotifications($event->getRoom()); }; $dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, $listener); $listener = static function(RoomEvent $event) { /** @var self $listener */ $listener = \OC::$server->query(self::class); + $listener->sendCallNotifications($event->getRoom()); + }; + $dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener); + + $listener = static function(RoomEvent $event) { + /** @var self $listener */ + $listener = \OC::$server->query(self::class); $listener->markCallNotificationsRead($event->getRoom()); }; $dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener); @@ -161,13 +171,28 @@ class Listener { * * @param Room $room */ - public function generateCallNotifications(Room $room): void { + public function checkCallNotifications(Room $room): void { if ($room->getActiveSince() instanceof \DateTime) { // Call already active => No new notifications + $this->shouldSendCallNotification = false; return; } if ($room->getObjectType() === 'file') { + $this->shouldSendCallNotification = false; + return; + } + + $this->shouldSendCallNotification = true; + } + + /** + * Call notification: "{user} wants to talk with you" + * + * @param Room $room + */ + public function sendCallNotifications(Room $room): void { + if (!$this->shouldSendCallNotification) { return; } |