|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * @copyright Copyright (c) 2020 Julien Veyssier <[email protected]> |
| 6 | + * |
| 7 | + * @author Julien Veyssier <[email protected]> |
| 8 | + * |
| 9 | + * @license GNU AGPL version 3 or any later version |
| 10 | + * |
| 11 | + * This program is free software: you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU Affero General Public License as |
| 13 | + * published by the Free Software Foundation, either version 3 of the |
| 14 | + * License, or (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace OCA\Talk\Controller; |
| 27 | + |
| 28 | +use OCA\Talk\Exceptions\ImpossibleToKillException; |
| 29 | +use OCA\Talk\Manager; |
| 30 | +use OCA\Talk\MatterbridgeManager; |
| 31 | +use OCP\AppFramework\Http; |
| 32 | +use OCP\AppFramework\Http\DataResponse; |
| 33 | +use OCP\IRequest; |
| 34 | + |
| 35 | +class MatterbridgeController extends AEnvironmentAwareController { |
| 36 | + /** @var string|null */ |
| 37 | + protected $userId; |
| 38 | + /** @var Manager */ |
| 39 | + protected $manager; |
| 40 | + /** @var MatterbridgeManager */ |
| 41 | + protected $bridgeManager; |
| 42 | + |
| 43 | + public function __construct(string $appName, |
| 44 | + ?string $UserId, |
| 45 | + IRequest $request, |
| 46 | + Manager $manager, |
| 47 | + MatterbridgeManager $bridgeManager) { |
| 48 | + parent::__construct($appName, $request); |
| 49 | + $this->userId = $UserId; |
| 50 | + $this->manager = $manager; |
| 51 | + $this->bridgeManager = $bridgeManager; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Get bridge information of one room |
| 56 | + * |
| 57 | + * @NoAdminRequired |
| 58 | + * @RequireLoggedInModeratorParticipant |
| 59 | + * |
| 60 | + * @return DataResponse |
| 61 | + */ |
| 62 | + public function getBridgeOfRoom(): DataResponse { |
| 63 | + $this->bridgeManager->checkBridge($this->room); |
| 64 | + $bridge = $this->bridgeManager->getBridgeOfRoom($this->room); |
| 65 | + return new DataResponse($bridge); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Edit bridge information of one room |
| 70 | + * |
| 71 | + * @NoAdminRequired |
| 72 | + * @RequireLoggedInModeratorParticipant |
| 73 | + * |
| 74 | + * @param bool $enabled |
| 75 | + * @param array $parts |
| 76 | + * @return DataResponse |
| 77 | + */ |
| 78 | + public function editBridgeOfRoom(bool $enabled, array $parts = []): DataResponse { |
| 79 | + try { |
| 80 | + $success = $this->bridgeManager->editBridgeOfRoom($this->room, $enabled, $parts); |
| 81 | + } catch (ImpossibleToKillException $e) { |
| 82 | + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE); |
| 83 | + } |
| 84 | + return new DataResponse($success); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Delete bridge of one room |
| 89 | + * |
| 90 | + * @NoAdminRequired |
| 91 | + * @RequireLoggedInModeratorParticipant |
| 92 | + * |
| 93 | + * @return DataResponse |
| 94 | + */ |
| 95 | + public function deleteBridgeOfRoom(): DataResponse { |
| 96 | + try { |
| 97 | + $success = $this->bridgeManager->deleteBridgeOfRoom($this->room); |
| 98 | + } catch (ImpossibleToKillException $e) { |
| 99 | + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE); |
| 100 | + } |
| 101 | + return new DataResponse($success); |
| 102 | + } |
| 103 | +} |
0 commit comments