summaryrefslogtreecommitdiffstats
path: root/lib/Notification/Listener.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-02-24 10:46:49 +0100
committerJoas Schilling <coding@schilljs.com>2022-02-24 11:51:29 +0100
commit2ba25785ffa8e9d94a5a25ac239c343beb6d6b26 (patch)
tree81e6d0f82f962e95fd95c91bc465bcf3e52373c6 /lib/Notification/Listener.php
parent4c0414e61dd819754be5ba29307f15ff9797b950 (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.php34
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();