Merge pull request #3347 from dpalou/MOBILE-4069

Mobile 4069
main
Noel De Martin 2022-07-14 16:20:10 +02:00 committed by GitHub
commit aaa98793aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 15 deletions

View File

@ -51,7 +51,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv
courseId: number,
regex?: RegExp,
siteId?: string,
): Promise<void> {
): Promise<boolean> {
regex = regex || /^.*files$|^timers/;
return super.prefetchAfterUpdate(prefetchHandler, module, courseId, regex, siteId);

View File

@ -205,21 +205,23 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
if (online && this.isPrefetched()) {
// The survey is downloaded, update the data.
try {
await AddonModSurveySync.prefetchAfterUpdate(
const prefetched = await AddonModSurveySync.prefetchAfterUpdate(
AddonModSurveyPrefetchHandler.instance,
this.module,
this.courseId,
);
// Update the view.
this.showLoadingAndFetch(false, false);
prefetched ?
this.showLoadingAndFetch(false, false) :
this.showLoadingAndRefresh(false);;
} catch {
// Prefetch failed, refresh the data.
await this.showLoadingAndRefresh(false);
this.showLoadingAndRefresh(false);
}
} else {
// Not downloaded, refresh the data.
await this.showLoadingAndRefresh(false);
this.showLoadingAndRefresh(false);
}
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_survey.cannotsubmitsurvey', true);

View File

@ -31,7 +31,7 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
* @param courseId Course ID.
* @param preventDownloadRegex If regex matches, don't download the data. Defaults to check files.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved when done.
* @return Promise resolved with boolean: true if prefetched, false if no need to prefetch.
*/
async prefetchAfterUpdate(
prefetchHandler: CoreCourseModulePrefetchHandlerBase,
@ -39,12 +39,12 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
courseId: number,
preventDownloadRegex?: RegExp,
siteId?: string,
): Promise<void> {
): Promise<boolean> {
// Get the module updates to check if the data was updated or not.
const result = await CoreCourseModulePrefetchDelegate.getModuleUpdates(module, courseId, true, siteId);
if (!result?.updates.length) {
return;
return false;
}
// Only prefetch if files haven't changed, to prevent downloading too much data automatically.
@ -52,8 +52,12 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
const shouldDownload = !result.updates.find((entry) => entry.name.match(regex));
if (shouldDownload) {
return prefetchHandler.download(module, courseId);
await prefetchHandler.download(module, courseId);
return true;
}
return false;
}
/**

View File

@ -772,13 +772,17 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
return { status: CoreConstants.NOT_DOWNLOADABLE };
}
// Get the stored data to get the status and downloadTime.
const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id);
try {
// Get the stored data to get the status and downloadTime.
const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id);
return {
status: data.status || CoreConstants.NOT_DOWNLOADED,
downloadTime: data.downloadTime || 0,
};
return {
status: data.status || CoreConstants.NOT_DOWNLOADED,
downloadTime: data.downloadTime || 0,
};
} catch {
return { status: CoreConstants.NOT_DOWNLOADED };
}
}
/**