Skip to content

Commit

Permalink
Merge branch 'MDL-77252-master' of https://github.com/davewoloszyn/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 25, 2023
2 parents 1cd51db + 5bad9bd commit d895574
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
36 changes: 36 additions & 0 deletions communication/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,40 @@ public function remove_members_from_room(array $userids, bool $queue = true): vo
);
}
}

/**
* Display the communication room status notification.
*/
public function show_communication_room_status_notification(): void {
// No communication, no room.
if (!$this->communication) {
return;
}

if ($this->communication->get_provider() === processor::PROVIDER_NONE) {
return;
}

$roomstatus = $this->get_communication_room_url() ? 'ready' : 'pending';
$pluginname = get_string('pluginname', $this->get_provider());
$message = get_string('communicationroom' . $roomstatus, 'communication', $pluginname);

switch ($roomstatus) {
case 'pending':

\core\notification::add($message, \core\notification::INFO);
break;

case 'ready':
// We only show the ready notification once per user.
// We check this with a custom user preference.
$roomreadypreference = "{$this->component}_{$this->instancetype}_{$this->instanceid}_room_ready";

if (empty(get_user_preferences($roomreadypreference))) {
\core\notification::add($message, \core\notification::SUCCESS);
set_user_preference($roomreadypreference, true);
}
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@communication @communication_matrix
Feature: Display communication room status banner
Show a banner depending on the room status
As a teacher or admin

Background:
Given a Matrix mock server is configured
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category | selectedcommunication | communicationroomname |
| Test course | Test course | 0 | communication_matrix | matrixroom |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | Test course | editingteacher |
| student1 | Test course | student |

Scenario: I can see the room has been created and in a pending status
When I am on the "Test course" "Course" page logged in as "teacher1"
Then I should see "Your Matrix room will be ready soon." in the "page-content" "region"
When I am on the "Test course" "Course" page logged in as "student1"
# Not for students to see.
Then I should not see "Your Matrix room will be ready soon." in the "page-content" "region"

Scenario: I can see the room has been created and ready to access
When I run all adhoc tasks
And I am on the "Test course" "Course" page logged in as "teacher1"
Then I should see "Your Matrix room is ready!" in the "page-content" "region"
# This is a one time message per user.
When I reload the page
Then I should not see "Your Matrix room is ready!" in the "page-content" "region"
# Not for students to see.
When I am on the "Test course" "Course" page logged in as "student1"
Then I should not see "Your Matrix room is ready!" in the "page-content" "region"
39 changes: 39 additions & 0 deletions communication/provider/matrix/tests/matrix_communication_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,4 +880,43 @@ public function test_delete_user_mappings_for_instance(): void {

$this->assertEmpty($communicationuserrecord);
}

/**
* Test status notifications of a communication room are generated correctly.
*
* @covers ::show_communication_room_status_notification
*/
public function test_show_communication_room_status_notification(): void {
$course = $this->get_course();

// Get communication api object.
$communication = \core_communication\api::load_by_instance(
'core_course',
'coursecommunication',
$course->id
);

// Room should be in 'pending' state before the task is run and show a notification.
$communication->show_communication_room_status_notification();

// Run the task.
$this->runAdhocTasks('\core_communication\task\create_and_configure_room_task');

// Get updated communication api after room configuration.
$communication = \core_communication\api::load_by_instance(
'core_course',
'coursecommunication',
$course->id
);

// Check the room is now in 'ready' state and show a notification.
$communication->show_communication_room_status_notification();

// Get our notifications stack.
// There should be one for 'pending' status, and one for 'ready' status.
$notifications = \core\notification::fetch();
$this->assertCount(2, $notifications);
$this->assertStringContainsString('Your Matrix room will be ready soon.', $notifications[0]->get_message());
$this->assertStringContainsString('Your Matrix room is ready!', $notifications[1]->get_message());
}
}
10 changes: 10 additions & 0 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();

// Show communication room status notification.
if (core_communication\api::is_available() && has_capability('moodle/course:update', $context)) {
$communication = \core_communication\api::load_by_instance(
'core_course',
'coursecommunication',
$course->id
);
$communication->show_communication_room_status_notification();
}

if ($USER->editing == 1) {

// MDL-65321 The backup libraries are quite heavy, only require the bare minimum.
Expand Down
2 changes: 2 additions & 0 deletions lang/en/communication.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
$string['communicationprovidernotfound'] = 'The \'{$a}\' communication provider doesn\'t exist or is not recognised.';
$string['communicationroomname'] = 'Room name';
$string['communicationroomname_help'] = 'The name that participants see when they visit the room. If you leave this blank, a default room name will be automatically set.';
$string['communicationroompending'] = 'Your {$a} room will be ready soon.';
$string['communicationroomready'] = 'Your {$a} room is ready!';
$string['managecommunicationproviders'] = 'Manage communication providers';
$string['nocommunicationprovider'] = 'No communication provider found.';
$string['nocommunicationselected'] = 'None';
Expand Down

0 comments on commit d895574

Please sign in to comment.