Skip to content

Commit

Permalink
Merge branch 'MDL-80403-403' of https://github.com/davewoloszyn/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_403_STABLE
  • Loading branch information
HuongNV13 committed Jan 18, 2024
2 parents 5881620 + cdb365b commit acecd19
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion communication/provider/matrix/classes/communication_feature.php
Expand Up @@ -190,6 +190,24 @@ public function create_members(array $userids): void {
}

public function update_room_membership(array $userids): void {

// Filter out any users that are not room members yet.
$response = $this->matrixapi->get_room_members(
roomid: $this->get_room_id(),
);
$body = self::get_body($response);

if (isset($body->joined)) {
foreach ($userids as $key => $userid) {
$matrixuserid = matrix_user_manager::get_matrixid_from_moodle(
userid: $userid,
);
if (!array_key_exists($matrixuserid, (array) $body->joined)) {
unset($userids[$key]);
}
}
}

$this->set_matrix_power_levels();
// Mark the users as synced for the updated members.
$this->processor->mark_users_as_synced($userids);
Expand Down Expand Up @@ -580,6 +598,12 @@ private function set_matrix_power_levels(
$currentpowerlevels = $this->get_current_powerlevel_data();
$currentuserpowerlevels = (array) $currentpowerlevels->users ?? [];

// Ensure each user entry is an array.
$currentuserpowerlevels = array_map(
fn ($user) => (array) $user,
$currentuserpowerlevels,
);

// Get all the current users who need to be in the room.
$userlist = $this->processor->get_all_userids_for_instance();

Expand Down Expand Up @@ -638,7 +662,10 @@ private function set_matrix_power_levels(
private function get_users_with_custom_power_level(array $users): array {
return array_filter(
$users,
function ($level): bool {
function ($user): bool {
// Isolate the level value.
$level = array_values($user);
$level = reset($level);
switch ($level) {
case matrix_constants::POWER_LEVEL_DEFAULT:
case matrix_constants::POWER_LEVEL_MOODLE_SITE_ADMIN:
Expand Down

0 comments on commit acecd19

Please sign in to comment.