diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-24 10:46:49 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-02-24 11:51:29 +0100 |
commit | 2ba25785ffa8e9d94a5a25ac239c343beb6d6b26 (patch) | |
tree | 81e6d0f82f962e95fd95c91bc465bcf3e52373c6 /lib/Notification/Listener.php | |
parent | 4c0414e61dd819754be5ba29307f15ff9797b950 (diff) |
Wrap notification generation in a transaction
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Listener.php')
-rw-r--r-- | lib/Notification/Listener.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index 891a06e96..065a1786b 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -31,6 +31,7 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\Notification\IManager; use OCP\IUser; use OCP\IUserSession; @@ -38,6 +39,8 @@ use Psr\Log\LoggerInterface; class Listener { + /** @var IDBConnection */ + protected $connection; /** @var IManager */ protected $notificationManager; /** @var ParticipantService */ @@ -54,12 +57,14 @@ class Listener { /** @var bool */ protected $shouldSendCallNotification = false; - public function __construct(IManager $notificationManager, + public function __construct(IDBConnection $connection, + IManager $notificationManager, ParticipantService $participantsService, IEventDispatcher $dispatcher, IUserSession $userSession, ITimeFactory $timeFactory, LoggerInterface $logger) { + $this->connection = $connection; $this->notificationManager = $notificationManager; $this->participantsService = $participantsService; $this->dispatcher = $dispatcher; @@ -248,18 +253,25 @@ class Listener { } $userIds = $this->participantsService->getParticipantUserIdsForCallNotifications($room); - foreach ($userIds as $userId) { - if ($actorId === $userId) { - continue; - } - - try { - $notification->setUser($userId); - $this->notificationManager->notify($notification); - } catch (\InvalidArgumentException $e) { - $this->logger->error($e->getMessage(), ['exception' => $e]); + $this->connection->beginTransaction(); + try { + foreach ($userIds as $userId) { + if ($actorId === $userId) { + continue; + } + + try { + $notification->setUser($userId); + $this->notificationManager->notify($notification); + } catch (\InvalidArgumentException $e) { + $this->logger->error($e->getMessage(), ['exception' => $e]); + } } + } catch (\Throwable $e) { + $this->connection->rollBack(); + throw $e; } + $this->connection->commit(); if ($shouldFlush) { $this->notificationManager->flush(); |