Skip to content
Merged
Changes from all commits
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
34 changes: 23 additions & 11 deletions lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
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;
use Psr\Log\LoggerInterface;

class Listener {

/** @var IDBConnection */
protected $connection;
/** @var IManager */
protected $notificationManager;
/** @var ParticipantService */
Expand All @@ -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;
Expand Down Expand Up @@ -248,18 +253,25 @@ public function sendCallNotifications(Room $room): void {
}

$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();
Expand Down