1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Julien Veyssier <eneiluj@posteo.net>
*
* @author Julien Veyssier <eneiluj@posteo.net>
* @author Kate Döen <kate.doeen@nextcloud.com>
*
* @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\Controller;
use OCA\Talk\Exceptions\ImpossibleToKillException;
use OCA\Talk\Manager;
use OCA\Talk\MatterbridgeManager;
use OCA\Talk\Middleware\Attribute\RequireLoggedInModeratorParticipant;
use OCA\Talk\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
/**
* @psalm-import-type TalkMatterbridge from ResponseDefinitions
* @psalm-import-type TalkMatterbridgeConfigFields from ResponseDefinitions
* @psalm-import-type TalkMatterbridgeProcessState from ResponseDefinitions
* @psalm-import-type TalkMatterbridgeWithProcessState from ResponseDefinitions
*/
class MatterbridgeController extends AEnvironmentAwareController {
public function __construct(
string $appName,
protected ?string $userId,
IRequest $request,
protected Manager $manager,
protected MatterbridgeManager $bridgeManager,
) {
parent::__construct($appName, $request);
}
/**
* Get bridge information of one room
*
* @return DataResponse<Http::STATUS_OK, TalkMatterbridgeWithProcessState, array{}>
*
* 200: Return list of configured bridges
*/
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function getBridgeOfRoom(): DataResponse {
$pid = $this->bridgeManager->checkBridge($this->room);
$logContent = $this->bridgeManager->getBridgeLog($this->room);
$bridge = $this->bridgeManager->getBridgeOfRoom($this->room);
$bridge['running'] = ($pid !== 0);
$bridge['log'] = $logContent;
return new DataResponse($bridge);
}
/**
* Get bridge process information
*
* @return DataResponse<Http::STATUS_OK, TalkMatterbridgeProcessState, array{}>
*
* 200: Return list of running processes
*/
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function getBridgeProcessState(): DataResponse {
$state = $this->bridgeManager->getBridgeProcessState($this->room);
return new DataResponse($state);
}
/**
* Edit bridge information of one room
*
* @param bool $enabled If the bridge should be enabled
* @param TalkMatterbridgeConfigFields $parts New parts
* @return DataResponse<Http::STATUS_OK, TalkMatterbridgeProcessState, array{}>|DataResponse<Http::STATUS_NOT_ACCEPTABLE, array{error: string}, array{}>
*
* 200: Bridge edited successfully
* 406: Editing bridge is not possible
*/
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function editBridgeOfRoom(bool $enabled, array $parts = []): DataResponse {
try {
$state = $this->bridgeManager->editBridgeOfRoom($this->room, $this->userId, $enabled, $parts);
} catch (ImpossibleToKillException $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE);
}
return new DataResponse($state);
}
/**
* Delete bridge of one room
*
* @return DataResponse<Http::STATUS_OK, bool, array{}>|DataResponse<Http::STATUS_NOT_ACCEPTABLE, array{error: string}, array{}>
*
* 200: Bridge deleted successfully
* 406: Deleting bridge is not possible
*/
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function deleteBridgeOfRoom(): DataResponse {
try {
$success = $this->bridgeManager->deleteBridgeOfRoom($this->room);
} catch (ImpossibleToKillException $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_ACCEPTABLE);
}
return new DataResponse($success);
}
}
|