diff --git a/appinfo/info.xml b/appinfo/info.xml index 156b7ee20..13daff604 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -17,7 +17,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m ]]> - 3.99.0 + 3.99.2 agpl Daniel Calviño Sánchez @@ -50,6 +50,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m OCA\Spreed\BackgroundJob\ExpireSignalingMessage OCA\Spreed\BackgroundJob\RemoveEmptyRooms + OCA\Spreed\BackgroundJob\ResetInCallFlags diff --git a/lib/BackgroundJob/RemoveEmptyRooms.php b/lib/BackgroundJob/RemoveEmptyRooms.php index b5af43ad6..246762b39 100644 --- a/lib/BackgroundJob/RemoveEmptyRooms.php +++ b/lib/BackgroundJob/RemoveEmptyRooms.php @@ -1,6 +1,6 @@ + * @copyright Copyright (c) 2018 Joas Schilling * * @license GNU AGPL version 3 or any later version * @@ -39,6 +39,8 @@ class RemoveEmptyRooms extends TimedJob { /** @var ILogger */ protected $logger; + protected $numDeletedRooms = 0; + public function __construct(Manager $manager, ILogger $logger) { // Every 5 minutes $this->setInterval(60 * 5); @@ -48,22 +50,23 @@ class RemoveEmptyRooms extends TimedJob { } protected function run($argument) { - $numDeletedRooms = 0; - $this->manager->forAllRooms(function(Room $room) use (&$numDeletedRooms) { - if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) { - $room->deleteRoom(); - $numDeletedRooms++; - } else if ($room->getNumberOfParticipants(false) === 0) { - $room->deleteRoom(); - $numDeletedRooms++; - } - }); + $this->manager->forAllRooms([$this, 'callback']); - if ($numDeletedRooms) { + if ($this->numDeletedRooms) { $this->logger->info('Deleted {numDeletedRooms} rooms because they were empty', [ - 'numDeletedRooms' => $numDeletedRooms, + 'numDeletedRooms' => $this->numDeletedRooms, 'app' => 'spreed', ]); } } + + protected function callback(Room $room) { + if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) { + $room->deleteRoom(); + $this->numDeletedRooms++; + } else if ($room->getNumberOfParticipants(false) === 0) { + $room->deleteRoom(); + $this->numDeletedRooms++; + } + } } diff --git a/lib/BackgroundJob/ResetInCallFlags.php b/lib/BackgroundJob/ResetInCallFlags.php new file mode 100644 index 000000000..dbff79a3a --- /dev/null +++ b/lib/BackgroundJob/ResetInCallFlags.php @@ -0,0 +1,75 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Spreed\BackgroundJob; + +use OC\BackgroundJob\TimedJob; +use OCA\Spreed\Exceptions\ParticipantNotFoundException; +use OCA\Spreed\Manager; +use OCA\Spreed\Room; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\ILogger; + +/** + * Class ResetInCallFlags + * + * @package OCA\Spreed\BackgroundJob + */ +class ResetInCallFlags extends TimedJob { + + /** @var Manager */ + protected $manager; + + /** @var int */ + protected $timeout; + + public function __construct(Manager $manager, ITimeFactory $timeFactory) { + // Every 5 minutes + $this->setInterval(60 * 5); + + $this->manager = $manager; + $this->timeout = $timeFactory->getTime() - 5 * 60; + } + + + protected function run($argument) { + $this->manager->forAllRooms([$this, 'callback']); + } + + protected function callback(Room $room) { + if (!$room->hasSessionsInCall()) { + return; + } + + foreach ($room->getActiveSessions() as $session) { + try { + $participant = $room->getParticipantBySession($session); + } catch (ParticipantNotFoundException $e) { + // Participant was just deleted, ignore … + continue; + } + + if ($participant->isInCall() && $participant->getLastPing() < $this->timeout) { + $room->changeInCall($session, false); + } + } + } +} diff --git a/lib/Manager.php b/lib/Manager.php index 5853daafb..bceb5a2b5 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -61,7 +61,7 @@ class Manager { $this->hasher = $hasher; } - public function forAllRooms(\Closure $callback) { + public function forAllRooms(callable $callback) { $query = $this->db->getQueryBuilder(); $query->select('*') ->from('talk_rooms');