forked from EVOgeek/Vmeda.Online
		
	MOBILE-2877 comments: Invalidate comments count
This commit is contained in:
		
							parent
							
								
									9e91cf14e6
								
							
						
					
					
						commit
						dc65d4a00d
					
				| @ -169,6 +169,10 @@ export class AddonBlogEntriesComponent implements OnInit { | ||||
|      * @param {any}     refresher  Refresher instance. | ||||
|      */ | ||||
|     refresh(refresher?: any): void { | ||||
|         this.entries.forEach((entry) => { | ||||
|             this.commentsProvider.invalidateCommentsData('user', entry.userid, this.component, entry.id, 'format_blog'); | ||||
|         }); | ||||
| 
 | ||||
|         this.blogProvider.invalidateEntries(this.filter).finally(() => { | ||||
|             this.fetchEntries(true).finally(() => { | ||||
|                 if (refresher) { | ||||
|  | ||||
| @ -218,6 +218,10 @@ export class AddonModDataEntryPage implements OnDestroy { | ||||
| 
 | ||||
|         promises.push(this.dataProvider.invalidateDatabaseData(this.courseId)); | ||||
|         if (this.data) { | ||||
|             if (this.data.comments && this.entry && this.entry.id > 0 && this.commentsEnabled) { | ||||
|                 promises.push(this.commentsProvider.invalidateCommentsData('module', this.data.coursemodule, 'mod_data', | ||||
|                     this.entry.id, 'database_entry')); | ||||
|             } | ||||
|             promises.push(this.dataProvider.invalidateEntryData(this.data.id, this.entryId)); | ||||
|             promises.push(this.groupsProvider.invalidateActivityGroupInfo(this.data.coursemodule)); | ||||
|             promises.push(this.dataProvider.invalidateEntriesData(this.data.id)); | ||||
|  | ||||
| @ -31,7 +31,6 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy { | ||||
|     @Input() component: string; | ||||
|     @Input() itemId: number; | ||||
|     @Input() area = ''; | ||||
|     @Input() page = 0; | ||||
|     @Input() title?: string; | ||||
|     @Input() displaySpinner = true; // Whether to display the loading spinner.
 | ||||
|     @Output() onLoading: EventEmitter<boolean>; // Eevent that indicates whether the component is loading data.
 | ||||
| @ -72,7 +71,7 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy { | ||||
|      */ | ||||
|     ngOnChanges(changes: { [name: string]: SimpleChange }): void { | ||||
|         // If something change, update the fields.
 | ||||
|         if (changes) { | ||||
|         if (changes && this.commentsLoaded) { | ||||
|             this.fetchData(); | ||||
|         } | ||||
|     } | ||||
| @ -108,7 +107,6 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy { | ||||
|                 component: this.component, | ||||
|                 itemId: this.itemId, | ||||
|                 area: this.area, | ||||
|                 page: this.page, | ||||
|                 title: this.title, | ||||
|             }); | ||||
|         } | ||||
|  | ||||
| @ -51,8 +51,8 @@ export class CoreCommentsViewerPage { | ||||
|         this.component = navParams.get('component'); | ||||
|         this.itemId = navParams.get('itemId'); | ||||
|         this.area = navParams.get('area') || ''; | ||||
|         this.page = navParams.get('page') || 0; | ||||
|         this.title = navParams.get('title') || this.translate.instant('core.comments.comments'); | ||||
|         this.page = 0; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -76,12 +76,11 @@ export class CoreCommentsProvider { | ||||
|      * @param  {string} component    Component name. | ||||
|      * @param  {number} itemId       Associated id. | ||||
|      * @param  {string} [area='']    String comment area. Default empty. | ||||
|      * @param  {number} [page=0]     Page number (0 based). Default 0. | ||||
|      * @return {string} Cache key. | ||||
|      */ | ||||
|     protected getCommentsCacheKey(contextLevel: string, instanceId: number, component: string, | ||||
|             itemId: number, area: string = '', page: number = 0): string { | ||||
|         return this.getCommentsPrefixCacheKey(contextLevel, instanceId) + ':' + component + ':' + itemId + ':' + area + ':' + page; | ||||
|     protected getCommentsCacheKey(contextLevel: string, instanceId: number, component: string, itemId: number, | ||||
|             area: string = ''): string { | ||||
|         return this.getCommentsPrefixCacheKey(contextLevel, instanceId) + ':' + component + ':' + itemId + ':' + area; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -107,8 +106,8 @@ export class CoreCommentsProvider { | ||||
|      * @param  {string} [siteId]     Site ID. If not defined, current site. | ||||
|      * @return {Promise<any>} Promise resolved with the comments. | ||||
|      */ | ||||
|     getComments(contextLevel: string, instanceId: number, component: string, itemId: number, | ||||
|             area: string = '', page: number = 0, siteId?: string): Promise<any> { | ||||
|     getComments(contextLevel: string, instanceId: number, component: string, itemId: number, area: string = '', page: number = 0, | ||||
|             siteId?: string): Promise<any> { | ||||
|         return this.sitesProvider.getSite(siteId).then((site) => { | ||||
|             const params: any = { | ||||
|                 contextlevel: contextLevel, | ||||
| @ -120,7 +119,7 @@ export class CoreCommentsProvider { | ||||
|             }; | ||||
| 
 | ||||
|             const preSets = { | ||||
|                 cacheKey: this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area, page), | ||||
|                 cacheKey: this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area), | ||||
|                 updateFrequency: CoreSite.FREQUENCY_SOMETIMES | ||||
|             }; | ||||
| 
 | ||||
| @ -142,14 +141,17 @@ export class CoreCommentsProvider { | ||||
|      * @param  {string} component    Component name. | ||||
|      * @param  {number} itemId       Associated id. | ||||
|      * @param  {string} [area='']    String comment area. Default empty. | ||||
|      * @param  {number} [page=0]     Page number (0 based). Default 0. | ||||
|      * @param  {string} [siteId]     Site ID. If not defined, current site. | ||||
|      * @return {Promise<any>} Promise resolved when the data is invalidated. | ||||
|      */ | ||||
|     invalidateCommentsData(contextLevel: string, instanceId: number, component: string, itemId: number, | ||||
|             area: string = '', page: number = 0, siteId?: string): Promise<any> { | ||||
|             area: string = '', siteId?: string): Promise<any> { | ||||
|         return this.sitesProvider.getSite(siteId).then((site) => { | ||||
|             return site.invalidateWsCacheForKey(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area, page)); | ||||
|             // This is done with starting with to avoid conflicts with previous keys that were including page.
 | ||||
|             site.invalidateWsCacheForKeyStartingWith(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, | ||||
|                 area) + ':'); | ||||
| 
 | ||||
|             return site.invalidateWsCacheForKey(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area)); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user