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 GuzzleHttp\Psr7\Response; 21 22 /** 23 * Matrix API feature to fetch room power levels using the sync API. 24 * 25 * https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3sync 26 * 27 * @package communication_matrix 28 * @copyright 2023 Andrew Lyons <andrew@nicols.co.uk> 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 * @codeCoverageIgnore 31 * This code does not warrant being tested. Testing offers no discernible benefit given its usage is tested. 32 */ 33 trait get_room_powerlevels_from_sync_v3 { 34 /** 35 * Get a list of room members. 36 * 37 * @param string $roomid The room ID 38 * @return Response 39 */ 40 public function get_room_power_levels(string $roomid): Response { 41 // Filter the event data according to the API: 42 // https://spec.matrix.org/v1.1/client-server-api/#filtering 43 // We have to filter out all of the object data that we do not want, 44 // and set a filter to only fetch the one room that we do want. 45 $filter = (object) [ 46 "account_data" => (object) [ 47 // We don't want any account info for this call. 48 "not_types" => ['*'], 49 ], 50 "event_fields" => [ 51 // We only care about type, and content. Not sender. 52 "type", 53 "content", 54 ], 55 "event_format" => "client", 56 "presence" => (object) [ 57 // We don't need any presence data. 58 "not_types" => ['*'], 59 ], 60 "room" => (object) [ 61 // We only want state information for power levels, not timeline and ephemeral data. 62 "rooms" => [ 63 $roomid, 64 ], 65 "state" => (object) [ 66 "types" => [ 67 "m.room.power_levels", 68 ], 69 ], 70 "ephemeral" => (object) [ 71 "not_types" => ['*'], 72 ], 73 "timeline" => (object) [ 74 "not_types" => ['*'], 75 ], 76 ], 77 ]; 78 79 $query = [ 80 'filter' => json_encode($filter), 81 ]; 82 83 return $this->execute(new command( 84 $this, 85 method: 'GET', 86 endpoint: '_matrix/client/v3/sync', 87 query: $query, 88 sendasjson: false, 89 )); 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body