From 0f4b02411e2cf6bed655c5250632f0537f4ef8c6 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 14 Dec 2023 14:48:48 +1100 Subject: [PATCH] MDL-80403 communication_matrix: Update membership checks membership --- .../matrix/classes/communication_feature.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/communication/provider/matrix/classes/communication_feature.php b/communication/provider/matrix/classes/communication_feature.php index cb8ed85229a..d784df3f171 100644 --- a/communication/provider/matrix/classes/communication_feature.php +++ b/communication/provider/matrix/classes/communication_feature.php @@ -190,6 +190,24 @@ class communication_feature implements } 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);