diff --git a/communication/classes/api.php b/communication/classes/api.php index 8e02e9a15cf95..b7b8e431b9bf7 100644 --- a/communication/classes/api.php +++ b/communication/classes/api.php @@ -427,6 +427,7 @@ public function get_provider(): string { * @param string $communicationroomname The communication room name * @param array $users The user ids to add to the room * @param null|\stored_file $instanceimage The stored file for the avatar + * @param bool $queue Queue the task for the provider room or not */ public function configure_room_and_membership_by_provider( string $provider, @@ -434,6 +435,7 @@ public function configure_room_and_membership_by_provider( string $communicationroomname, array $users, ?\stored_file $instanceimage = null, + bool $queue = true, ): void { // If the current provider is inactive and the new provider is also none, then nothing to do. if ( @@ -456,6 +458,7 @@ public function configure_room_and_membership_by_provider( communicationroomname: $communicationroomname, avatar: $instanceimage, instance: $instance, + queue: $queue, ); return; } @@ -474,6 +477,7 @@ public function configure_room_and_membership_by_provider( communicationroomname: $communicationroomname, avatar: $instanceimage, instance: $instance, + queue: $queue, ); } @@ -492,8 +496,9 @@ public function configure_room_and_membership_by_provider( communicationroomname: $communicationroomname, avatar: $instanceimage, instance: $instance, + queue: $queue, ); - $queue = false; + $queueusertask = false; } else { // Otherwise update the room. $this->update_room( @@ -501,14 +506,15 @@ public function configure_room_and_membership_by_provider( communicationroomname: $communicationroomname, avatar: $instanceimage, instance: $instance, + queue: $queue, ); - $queue = true; + $queueusertask = true; } // Now add the members. $this->add_members_to_room( userids: $users, - queue: $queue, + queue: $queueusertask, ); } diff --git a/communication/classes/helper.php b/communication/classes/helper.php index 5bc8606286659..5a691669d3121 100644 --- a/communication/classes/helper.php +++ b/communication/classes/helper.php @@ -480,30 +480,21 @@ public static function update_course_communication_instance( $communication = self::load_by_course( courseid: $course->id, context: $coursecontext, - provider: $provider === processor::PROVIDER_NONE ? null : $provider, ); - if ($communication->get_processor() === null) { - // If a course communication instance is not created, create one. - $communication->create_and_configure_room( - communicationroomname: $course->communicationroomname, - avatar: $courseimage, - instance: $course, - queue: false, - ); - } else { - $communication->remove_all_members_from_room(); - // Now update the course communication instance with the latest changes. - // We are not making room for this instance as it is a group mode enabled course. - // If provider is none, then we will make the room inactive, otherwise always active in group mode. - $communication->update_room( - active: $provider === processor::PROVIDER_NONE ? processor::PROVIDER_INACTIVE : processor::PROVIDER_ACTIVE, - communicationroomname: $course->communicationroomname, - avatar: $courseimage, - instance: $course, - queue: false, - ); - } + // Now handle the course communication according to the provider. + $communication->configure_room_and_membership_by_provider( + provider: $provider, + instance: $course, + communicationroomname: $course->communicationroomname, + users: $enrolledusers, + instanceimage: $courseimage, + queue: false, + ); + + // As the course is in group mode, make sure no users are in the course room. + $communication->reload(); + $communication->remove_all_members_from_room(); } }