<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Julien Veyssier <eneiluj@posteo.net>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talk;
use OC\Authentication\Token\IProvider as IAuthTokenProvider;
use OC\Authentication\Token\IToken;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Exceptions\ImpossibleToKillException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\WrongPermissionsException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
class MatterbridgeManager {
public const BRIDGE_BOT_USERID = 'bridge-bot';
/** @var IDBConnection */
private $db;
/** @var IConfig */
private $config;
/** @var IURLGenerator */
private $urlGenerator;
/** @var IUserManager */
private $userManager;
/** @var Manager */
private $manager;
/** @var ParticipantService */
private $participantService;
/** @var ChatManager */
private $chatManager;
/** @var IAuthTokenProvider */
private $tokenProvider;
/** @var ISecureRandom */
private $random;
/** @var IAvatarManager */
private $avatarManager;
/** @var LoggerInterface */
private $logger;
/** @var ITimeFactory */
private $timeFactory;
public function __construct(IDBConnection $db,
IConfig $config,
IURLGenerator $urlGenerator,
IUserManager $userManager,
Manager $manager,
ParticipantService $participantService,
ChatManager $chatManager,
IAuthTokenProvider $tokenProvider,
ISecureRandom $random,
IAvatarManager $avatarManager,
LoggerInterface $logger,
ITimeFactory $timeFactory) {
$this->avatarManager = $avatarManager;
$this->db = $db;
$this->config = $config;
$this->urlGenerator = $urlGenerator;
$this->userManager = $userManager;
$this->manager = $manager;
$this->participantService = $participantService;
$this->chatManager = $chatManager;
$this->tokenProvider = $tokenProvider;
$this->random = $random;
$this->logger = $logger;
$this->timeFactory = $timeFactory;
}
/**
* Get bridge information for a specific room
*
* @param Room $room the room
* @return array decoded json bridge information
*/
public function getBridgeOfRoom(Room $room): array {
return $this->getBridgeFromDb($room);
}
/**
* Get bridge process information for a specific room
*
* @param Room $room the room
* @return array process state and log
*/
public function getBridgeProcessState(Room $room): array {
$bridge = $this->getBridgeFromDb($room);
$logContent = $this->getBridgeLog($room);
$pid = $this->checkBridgeProcess($room, $bridge, false);
return [
'running' => ($pid !== 0),