diff --git a/src/addons/mod/lesson/components/index/index.ts b/src/addons/mod/lesson/components/index/index.ts index d2e6204b5..d4cd33b9b 100644 --- a/src/addons/mod/lesson/components/index/index.ts +++ b/src/addons/mod/lesson/components/index/index.ts @@ -417,8 +417,16 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo this.dataSentObserver?.off(); this.dataSentObserver = CoreEvents.on(AddonModLessonProvider.DATA_SENT_EVENT, (data) => { - // Ignore launch sending because it only affects timers. - if (data.lessonId === this.lesson?.id && data.type != 'launch') { + if (data.lessonId !== this.lesson?.id || data.type === 'launch') { + // Ignore launch sending because it only affects timers. + return; + } + + if (data.type === 'finish') { + // Lesson finished, check completion now. + this.dataSent = false; + this.checkCompletion(); + } else { this.dataSent = true; } }, this.siteId); diff --git a/src/addons/mod/scorm/components/index/index.ts b/src/addons/mod/scorm/components/index/index.ts index ddc814819..ebf47cfa3 100644 --- a/src/addons/mod/scorm/components/index/index.ts +++ b/src/addons/mod/scorm/components/index/index.ts @@ -16,6 +16,7 @@ import { CoreConstants } from '@/core/constants'; import { Component, OnInit, Optional } from '@angular/core'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; +import { CoreCourse } from '@features/course/services/course'; import { IonContent } from '@ionic/angular'; import { CoreNavigator } from '@services/navigator'; import { CoreSync } from '@services/sync'; @@ -542,6 +543,11 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom this.dataSentObserver = CoreEvents.on(AddonModScormProvider.DATA_SENT_EVENT, (data) => { if (data.scormId === this.scorm!.id) { this.dataSent = true; + + if (this.module.completiondata && CoreCourse.isIncompleteAutomaticCompletion(this.module.completiondata)) { + // Always invalidate section data when data is sent, the SCORM could have a link to a section. + CoreCourse.invalidateSections(this.courseId); + } } }, this.siteId); diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 4ad01748f..cfe4ab4e3 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -227,8 +227,7 @@ export class CoreCourseProvider { * @param completion Completion status of the module. */ checkModuleCompletion(courseId: number, completion?: CoreCourseModuleCompletionData): void { - if (completion && completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC && - completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE) { + if (completion && this.isIncompleteAutomaticCompletion(completion)) { this.invalidateSections(courseId).finally(() => { CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, { courseId: courseId, @@ -238,6 +237,17 @@ export class CoreCourseProvider { } } + /** + * Given some completion data, return whether it's an automatic completion that hasn't been completed yet. + * + * @param completion Completion data. + * @return Whether it's an automatic completion that hasn't been completed yet. + */ + isIncompleteAutomaticCompletion(completion: CoreCourseModuleCompletionData): boolean { + return completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC && + completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE; + } + /** * Clear all courses status in a site. *