forked from EVOgeek/Vmeda.Online
		
	Merge pull request #2903 from dpalou/MOBILE-3775
MOBILE-3775 course: Fix PTR not updating contents in some resources
This commit is contained in:
		
						commit
						36f4d33f6b
					
				| @ -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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -321,28 +321,33 @@ 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') { | ||||
|     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) { | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 // The status has changed, update it.
 | ||||
|                 const previousStatus = this.currentStatus; | ||||
|                 this.currentStatus = data.status; | ||||
| 
 | ||||
|                 this.showStatus(this.currentStatus, previousStatus); | ||||
|             }, this.siteId); | ||||
|         } else if (!refresh) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // 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) { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             // The status has changed, update it.
 | ||||
|             const previousStatus = this.currentStatus; | ||||
|             this.currentStatus = data.status; | ||||
| 
 | ||||
|             this.showStatus(this.currentStatus, previousStatus); | ||||
|         }, this.siteId); | ||||
|         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.
 | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -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. | ||||
|      */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user