-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(calls): Allow to enforce a maximum call length
Signed-off-by: Joas Schilling <[email protected]>
- Loading branch information
1 parent
79805c8
commit 289d82e
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Talk\BackgroundJob; | ||
|
||
use OCA\Talk\Manager; | ||
use OCA\Talk\Service\ParticipantService; | ||
use OCA\Talk\Service\RoomService; | ||
use OCP\AppFramework\Services\IAppConfig; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\BackgroundJob\TimedJob; | ||
|
||
class MaximumCallDuration extends TimedJob { | ||
public function __construct( | ||
private IAppConfig $appConfig, | ||
private Manager $manager, | ||
private RoomService $roomService, | ||
private ParticipantService $participantService, | ||
ITimeFactory $time, | ||
) { | ||
parent::__construct($time); | ||
|
||
// Every time the jobs run | ||
$this->setInterval(1); | ||
} | ||
|
||
protected function run($argument): void { | ||
$maxCallDuration = $this->appConfig->getAppValueInt('max_call_duration'); | ||
if ($maxCallDuration <= 0) { | ||
return; | ||
} | ||
|
||
$now = $this->time->getDateTime(); | ||
$maxActiveSince = $now->sub(new \DateInterval('PT' . $maxCallDuration . 'S')); | ||
$rooms = $this->manager->getRoomsLongerActiveSince($maxActiveSince); | ||
|
||
foreach ($rooms as $room) { | ||
if ($room->isFederatedConversation()) { | ||
continue; | ||
} | ||
|
||
$result = $this->roomService->resetActiveSinceInDatabaseOnly($room); | ||
if (!$result) { | ||
// Someone else won the race condition, make sure this user disconnects directly and then return | ||
continue; | ||
} | ||
|
||
$this->participantService->endCallForEveryone($room, null); | ||
$this->roomService->resetActiveSinceInModelOnly($room); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters