Merge pull request #2903 from dpalou/MOBILE-3775

MOBILE-3775 course: Fix PTR not updating contents in some resources
main
Pau Ferrer Ocaña 2021-07-29 11:53:30 +02:00 committed by GitHub
commit 36f4d33f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 21 deletions

View File

@ -186,7 +186,8 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
// Ignore errors, they're handled inside the loadChapter function.
}
} finally {
this.fillContextMenu(refresh);
// Pass false because downloadResourceIfNeeded already invalidates and refresh data if refresh=true.
this.fillContextMenu(false);
}
}

View File

@ -117,7 +117,8 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom
this.warning = downloadResult!.failed ? this.getErrorDownloadingSomeFilesMessage(downloadResult!.error!) : '';
} finally {
this.fillContextMenu(refresh);
// Pass false because downloadResourceIfNeeded already invalidates and refresh data if refresh=true.
this.fillContextMenu(false);
}
}

View File

@ -143,7 +143,8 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp
await Promise.all(promises);
} finally {
this.fillContextMenu(refresh);
// Pass false because downloadResourceIfNeeded already invalidates and refresh data if refresh=true.
this.fillContextMenu(false);
}
}

View File

@ -114,6 +114,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
let resource: AddonModResourceResource | CoreCourseWSModule | undefined;
let options: AddonModResourceCustomData = {};
let hasCalledDownloadResource = false;
// Get the resource instance to get the latest name/description and to know if it's embedded.
if (this.canGetResource) {
@ -133,6 +134,8 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
}
if (AddonModResourceHelper.isDisplayedInIframe(this.module)) {
hasCalledDownloadResource = true;
const downloadResult = await this.downloadResourceIfNeeded(refresh, true);
const src = await AddonModResourceHelper.getIframeSrc(this.module);
this.mode = 'iframe';
@ -174,7 +177,8 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
this.isStreamedFile = CoreMimetypeUtils.isStreamedMimetype(mimetype);
}
} finally {
this.fillContextMenu(refresh);
// Pass false in some cases because downloadResourceIfNeeded already invalidates and refresh data if refresh=true.
this.fillContextMenu(hasCalledDownloadResource ? false : refresh);
}
}

View File

@ -321,13 +321,11 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
/**
* Watch for changes on the status.
*
* @param refresh Whether we're refreshing data.
* @return Promise resolved when done.
*/
protected async setStatusListener(): Promise<void> {
if (typeof this.statusObserver != 'undefined') {
return;
}
protected async setStatusListener(refresh?: boolean): Promise<void> {
if (this.statusObserver === undefined) {
// Listen for changes on this module status.
this.statusObserver = CoreEvents.on(CoreEvents.PACKAGE_STATUS_CHANGED, (data) => {
if (data.componentId != this.module.id || data.component != this.component) {
@ -340,9 +338,16 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
this.showStatus(this.currentStatus, previousStatus);
}, this.siteId);
} else if (!refresh) {
return;
}
if (refresh) {
await CoreUtils.ignoreErrors(CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(this.courseId));
}
// Also, get the current status.
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(this.module, this.courseId);
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(this.module, this.courseId, undefined, refresh);
this.currentStatus = status;
this.showStatus(status);
@ -366,7 +371,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
};
// Get module status to determine if it needs to be downloaded.
await this.setStatusListener();
await this.setStatusListener(refresh);
if (this.currentStatus != CoreConstants.DOWNLOADED) {
// Download content. This function also loads module contents if needed.

View File

@ -1455,6 +1455,8 @@ export class CoreCourseHelperProvider {
const siteId = CoreSites.getCurrentSiteId();
if (invalidateCache) {
// Currently, some modules pass invalidateCache=false because they already invalidate data in downloadResourceIfNeeded.
// If this function is changed to do more actions if invalidateCache=true, please review those modules.
CoreCourseModulePrefetchDelegate.invalidateModuleStatusCache(module);
}

View File

@ -546,7 +546,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to.
* @param updates Result of getCourseUpdates for all modules in the course. If not provided, it will be
* calculated (slower). If it's false it means the site doesn't support check updates.
* @param refresh True if it should ignore the cache.
* @param refresh True if it should ignore the memory cache, not the WS cache.
* @param sectionId ID of the section the module belongs to.
* @return Promise resolved with the status.
*/