From 03e9bcb7366d071f374e7622ebdcedd94d9b6f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 31 Jan 2024 13:33:06 +0100 Subject: [PATCH] MOBILE-4243 course: Add communication room button to course page --- scripts/langindex.json | 1 + src/core/classes/sites/authenticated-site.ts | 1 + .../course-format/course-format.html | 11 +++++-- .../components/course-format/course-format.ts | 4 +++ src/core/features/course/lang.json | 1 + .../features/course/services/course-helper.ts | 23 ++++++++++++++ .../course/tests/behat/communication.feature | 30 +++++++++++++++++++ src/core/features/courses/services/courses.ts | 2 ++ 8 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/core/features/course/tests/behat/communication.feature diff --git a/scripts/langindex.json b/scripts/langindex.json index dde73d532..507d94e0b 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1570,6 +1570,7 @@ "core.course.aria:sectionprogress": "local_moodlemobileapp", "core.course.availablespace": "local_moodlemobileapp", "core.course.cannotdeletewhiledownloading": "local_moodlemobileapp", + "core.course.communicationroomlink": "course", "core.course.completion_automatic:done": "course", "core.course.completion_automatic:failed": "course", "core.course.completion_automatic:todo": "course", diff --git a/src/core/classes/sites/authenticated-site.ts b/src/core/classes/sites/authenticated-site.ts index 4fd6fb9fd..d013a5a80 100644 --- a/src/core/classes/sites/authenticated-site.ts +++ b/src/core/classes/sites/authenticated-site.ts @@ -72,6 +72,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite { '4.1': 2022112800, '4.2': 2023042400, '4.3': 2023100900, + '4.4': 2024012500, // @TODO correct the final release date. }; // Possible cache update frequencies. diff --git a/src/core/features/course/components/course-format/course-format.html b/src/core/features/course/components/course-format/course-format.html index 6030b40f0..8a837aa6a 100644 --- a/src/core/features/course/components/course-format/course-format.html +++ b/src/core/features/course/components/course-format/course-format.html @@ -50,9 +50,14 @@ [instanceId]="course.id" /> - - + + + + diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index 06c8e6c7d..eb6419702 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -117,6 +117,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { viewedModules: Record = {}; completionStatusIncomplete = CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE; + communicationRoomUrl?: string; + protected selectTabObserver?: CoreEventObserver; protected modViewedObserver?: CoreEventObserver; protected lastCourseFormat?: string; @@ -197,6 +199,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.displayBlocks = CoreCourseFormatDelegate.displayBlocks(this.course); this.hasBlocks = await CoreBlockHelper.hasCourseBlocks(this.course.id); + + this.communicationRoomUrl = await CoreCourseHelper.getCourseCommunicationRoom(this.course); } if (changes.sections && this.sections) { diff --git a/src/core/features/course/lang.json b/src/core/features/course/lang.json index 00cea37a3..11b455eaf 100644 --- a/src/core/features/course/lang.json +++ b/src/core/features/course/lang.json @@ -5,6 +5,7 @@ "aria:sectionprogress": "Section progress:", "availablespace": "You currently have about {{available}} free space.", "cannotdeletewhiledownloading": "Files cannot be deleted while the activity is being downloaded. Please wait for the download to finish.", + "communicationroomlink": "Chat to course participants", "completion_automatic:done": "Done:", "completion_automatic:failed": "Failed:", "completion_automatic:todo": "To do:", diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index cbc0fd3db..e2594b104 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -2031,6 +2031,29 @@ export class CoreCourseHelperProvider { ); } + /** + * Get course communication room URL. + * + * @param course Course. + * @returns Promise resolved with the URL. + */ + async getCourseCommunicationRoom(course: CoreCourseAnyCourseData): Promise { + + const site = CoreSites.getRequiredCurrentSite(); + if (!site.isVersionGreaterEqualThan('4.4')) { + return; + } + + if ('communicationroomurl' in course) { + return course.communicationroomurl; + } + + course = await CoreCourses.getCourseByField('id', course.id, site.id); + if ('communicationroomurl' in course) { + return course.communicationroomurl; + } + } + } export const CoreCourseHelper = makeSingleton(CoreCourseHelperProvider); diff --git a/src/core/features/course/tests/behat/communication.feature b/src/core/features/course/tests/behat/communication.feature new file mode 100644 index 000000000..cbfe8c954 --- /dev/null +++ b/src/core/features/course/tests/behat/communication.feature @@ -0,0 +1,30 @@ +@core_course @app @javascript @lms_from4.4 +Feature: Use custom communication link in course + + Background: + Given 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 | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following config values are set as admin: + | enablecommunicationsubsystem | 1 | + And I am on the "Course 1" "Course" page logged in as "teacher1" + And I navigate to "Communication" in current page administration + And I select "Custom link" from the "Provider" singleselect + And I set the following fields to these values: + | communicationroomname | Test URL | + | customlinkurl | #wwwroot#/communication/provider/customlink/tests/behat/fixtures/custom_link_test_page.php | + And I press "Save changes" + + Scenario: Use communication link + Given I entered the course "Course 1" as "student1" in the app + And I press "Chat to course participants" in the app + And I press "OK" in the app + Then the app should have opened a browser tab with url ".*\/communication\/provider\/customlink\/tests\/behat\/fixtures\/custom_link_test_page.php" diff --git a/src/core/features/courses/services/courses.ts b/src/core/features/courses/services/courses.ts index 89f45d9f0..cf30f5e9d 100644 --- a/src/core/features/courses/services/courses.ts +++ b/src/core/features/courses/services/courses.ts @@ -1416,6 +1416,8 @@ export type CoreCourseSearchedData = CoreCourseBasicSearchedData & { inheritedstate: number; // 1 or 0 to use when localstate is set to inherit. }[]; courseformatoptions?: CoreCourseFormatOption[]; // Additional options for particular course format. + communicationroomname?: string; // @since Moodle 4.4. Communication tool room name. + communicationroomurl?: string; // @since Moodle 4.4. Communication tool room URL. }; /**