1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace communication_matrix\local\spec\features\matrix;
|
|
|
18 |
|
|
|
19 |
use communication_matrix\local\command;
|
|
|
20 |
use communication_matrix\matrix_constants;
|
|
|
21 |
use GuzzleHttp\Psr7\Response;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Matrix API feature to update a room power levels.
|
|
|
25 |
*
|
|
|
26 |
* Matrix rooms have a concept of power levels, which are used to determine what actions a user can perform in a room.
|
|
|
27 |
*
|
|
|
28 |
* https://spec.matrix.org/v1.1/client-server-api/#mroompower_levels
|
|
|
29 |
*
|
|
|
30 |
* @package communication_matrix
|
|
|
31 |
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
* @codeCoverageIgnore
|
|
|
34 |
* This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested.
|
|
|
35 |
*/
|
|
|
36 |
trait update_room_power_levels_v3 {
|
|
|
37 |
/**
|
|
|
38 |
* Set the avatar for a room to the specified URL.
|
|
|
39 |
*
|
|
|
40 |
* @param string $roomid The roomid to set for
|
|
|
41 |
* @param array $users The users to set power levels for
|
|
|
42 |
* @param int $ban The level required to ban a user
|
|
|
43 |
* @param int $invite The level required to invite a user
|
|
|
44 |
* @param int $kick The level required to kick a user
|
|
|
45 |
* @param array $notifications The level required to send notifications
|
|
|
46 |
* @param int $redact The level required to redact events
|
|
|
47 |
* @return Response
|
|
|
48 |
*/
|
|
|
49 |
public function update_room_power_levels(
|
|
|
50 |
string $roomid,
|
|
|
51 |
array $users,
|
|
|
52 |
int $ban = matrix_constants::POWER_LEVEL_MAXIMUM,
|
|
|
53 |
int $invite = matrix_constants::POWER_LEVEL_MODERATOR,
|
|
|
54 |
int $kick = matrix_constants::POWER_LEVEL_MODERATOR,
|
|
|
55 |
array $notifications = [
|
|
|
56 |
'room' => matrix_constants::POWER_LEVEL_MODERATOR,
|
|
|
57 |
],
|
|
|
58 |
int $redact = matrix_constants::POWER_LEVEL_MODERATOR,
|
|
|
59 |
): Response {
|
|
|
60 |
$params = [
|
|
|
61 |
':roomid' => $roomid,
|
|
|
62 |
'ban' => $ban,
|
|
|
63 |
'invite' => $invite,
|
|
|
64 |
'kick' => $kick,
|
|
|
65 |
'notifications' => $notifications,
|
|
|
66 |
'redact' => $redact,
|
|
|
67 |
'users' => $users,
|
|
|
68 |
];
|
|
|
69 |
|
|
|
70 |
return $this->execute(new command(
|
|
|
71 |
$this,
|
|
|
72 |
method: 'PUT',
|
|
|
73 |
endpoint: '_matrix/client/v3/rooms/:roomid/state/m.room.power_levels',
|
|
|
74 |
params: $params,
|
|
|
75 |
));
|
|
|
76 |
}
|
|
|
77 |
}
|