forked from EVOgeek/Vmeda.Online
		
	MOBILE-3855 resource: Fix activity not found for new resources
This commit is contained in:
		
							parent
							
								
									cce45996a0
								
							
						
					
					
						commit
						c037a8ea17
					
				| @ -89,6 +89,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom | |||||||
|         component: AddonModForumSortOrderSelectorComponent, |         component: AddonModForumSortOrderSelectorComponent, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |     protected fetchContentDefaultError = 'addon.mod_forum.errorgetforum'; | ||||||
|     protected syncEventName = AddonModForumSyncProvider.AUTO_SYNCED; |     protected syncEventName = AddonModForumSyncProvider.AUTO_SYNCED; | ||||||
|     protected syncManualObserver?: CoreEventObserver; // It will observe the sync manual event.
 |     protected syncManualObserver?: CoreEventObserver; // It will observe the sync manual event.
 | ||||||
|     protected replyObserver?: CoreEventObserver; |     protected replyObserver?: CoreEventObserver; | ||||||
| @ -325,18 +326,13 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom | |||||||
|                 }), |                 }), | ||||||
|             ]); |             ]); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|             if (refresh) { |  | ||||||
|                 CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.errorgetforum', true); |  | ||||||
| 
 |  | ||||||
|             this.fetchFailed = true; // Set to prevent infinite calls with infinite-loading.
 |             this.fetchFailed = true; // Set to prevent infinite calls with infinite-loading.
 | ||||||
|             } else { |  | ||||||
|                 // Get forum failed, retry without using cache since it might be a new activity.
 |  | ||||||
|                 await this.refreshContent(sync); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|  |             throw error; // Pass the error to the parent catch.
 | ||||||
|  |         } finally { | ||||||
|             this.fillContextMenu(refresh); |             this.fillContextMenu(refresh); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     private async fetchForum(sync: boolean = false, showErrors: boolean = false): Promise<void> { |     private async fetchForum(sync: boolean = false, showErrors: boolean = false): Promise<void> { | ||||||
|         if (!this.courseId || !this.module) { |         if (!this.courseId || !this.module) { | ||||||
|  | |||||||
| @ -208,8 +208,8 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR | |||||||
| 
 | 
 | ||||||
|             await this.fetchContent(refresh, sync, showErrors); |             await this.fetchContent(refresh, sync, showErrors); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|             if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled()) { |             if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled() && this.isNotFoundError(error)) { | ||||||
|                 // Some call failed, retry without using cache since it might be a new activity.
 |                 // Module not found, retry without using cache.
 | ||||||
|                 return await this.refreshContent(sync); |                 return await this.refreshContent(sync); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ import { AddonBlog } from '@addons/blog/services/blog'; | |||||||
| import { AddonBlogMainMenuHandlerService } from '@addons/blog/services/handlers/mainmenu'; | import { AddonBlogMainMenuHandlerService } from '@addons/blog/services/handlers/mainmenu'; | ||||||
| import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; | import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; | ||||||
| import { Params } from '@angular/router'; | import { Params } from '@angular/router'; | ||||||
|  | import { CoreAnyError } from '@classes/errors/error'; | ||||||
| import { IonRefresher } from '@ionic/angular'; | import { IonRefresher } from '@ionic/angular'; | ||||||
| import { CoreApp } from '@services/app'; | import { CoreApp } from '@services/app'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
| @ -212,6 +213,11 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, | |||||||
|         try { |         try { | ||||||
|             await this.fetchContent(refresh); |             await this.fetchContent(refresh); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|  |             if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled() && this.isNotFoundError(error)) { | ||||||
|  |                 // Module not found, retry without using cache.
 | ||||||
|  |                 return await this.refreshContent(); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             CoreDomUtils.showErrorModalDefault(error, this.fetchContentDefaultError, true); |             CoreDomUtils.showErrorModalDefault(error, this.fetchContentDefaultError, true); | ||||||
|         } finally { |         } finally { | ||||||
|             this.loaded = true; |             this.loaded = true; | ||||||
| @ -219,6 +225,16 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if an error is a "module not found" error. | ||||||
|  |      * | ||||||
|  |      * @param error Error. | ||||||
|  |      * @return Whether the error is a "module not found" error. | ||||||
|  |      */ | ||||||
|  |     protected isNotFoundError(error: CoreAnyError): boolean { | ||||||
|  |         return CoreTextUtils.getErrorMessageFromError(error) === Translate.instant('core.course.modulenotfound'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Fill the context menu options |      * Fill the context menu options | ||||||
|      */ |      */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user