From 204a1ce8f1daf3a249184e956481524cbf628d4a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 19 Jul 2018 11:49:25 +0200 Subject: [PATCH 1/2] MOBILE-2512 prefetch: Don't download hidden modules and sections --- src/core/course/providers/helper.ts | 5 +++++ src/core/course/providers/module-prefetch-delegate.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index d5a27649b..11d5a869f 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -1114,6 +1114,11 @@ export class CoreCourseHelperProvider { return Promise.resolve(); } + if (section.hiddenbynumsections) { + // Hidden section. + return Promise.resolve(); + } + section.isDownloading = true; // Validate the section needs to be downloaded and calculate amount of modules that need to be downloaded. diff --git a/src/core/course/providers/module-prefetch-delegate.ts b/src/core/course/providers/module-prefetch-delegate.ts index 50f0e22de..722a2cc59 100644 --- a/src/core/course/providers/module-prefetch-delegate.ts +++ b/src/core/course/providers/module-prefetch-delegate.ts @@ -953,6 +953,11 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { * @return {Promise} Promise resolved with true if downloadable, false otherwise. */ isModuleDownloadable(module: any, courseId: number): Promise { + if (module.uservisible === false) { + // Module isn't visible by the user, cannot be downloaded. + return Promise.resolve(false); + } + const handler = this.getPrefetchHandlerFor(module); if (handler) { From 424f5e324fd26bcb1faf1457fa85ce1678745c71 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 19 Jul 2018 12:14:20 +0200 Subject: [PATCH 2/2] MOBILE-2512 workshop: Avoid error when downloading profiles in workshop --- src/addon/mod/workshop/providers/prefetch-handler.ts | 4 +++- src/core/user/providers/user.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/addon/mod/workshop/providers/prefetch-handler.ts b/src/addon/mod/workshop/providers/prefetch-handler.ts index 6c5762737..5168d2a5e 100644 --- a/src/addon/mod/workshop/providers/prefetch-handler.ts +++ b/src/addon/mod/workshop/providers/prefetch-handler.ts @@ -363,7 +363,9 @@ export class AddonModWorkshopPrefetchHandler extends CoreCourseActivityPrefetchH }); }).then(() => { // Prefetch user profiles. - return this.userProvider.prefetchProfiles(userIds, courseId, siteId); + return this.userProvider.prefetchProfiles(userIds, courseId, siteId).catch(() => { + // Ignore errors. + }); }); } } diff --git a/src/core/user/providers/user.ts b/src/core/user/providers/user.ts index 6cb79a6f4..45795a971 100644 --- a/src/core/user/providers/user.ts +++ b/src/core/user/providers/user.ts @@ -383,6 +383,10 @@ export class CoreUserProvider { promises = []; userIds.forEach((userId) => { + if (userId === null) { + return; + } + userId = Number(userId); // Make sure it's a number. // Prevent repeats and errors.