forked from EVOgeek/Vmeda.Online
		
	MOBILE-4317 calendar: Schedule new site reminders
This commit is contained in:
		
							parent
							
								
									3d0a9441f4
								
							
						
					
					
						commit
						d1f28f43ab
					
				| @ -49,6 +49,7 @@ import { | |||||||
|     CoreReminderValueAndUnit, |     CoreReminderValueAndUnit, | ||||||
| } from '@features/reminders/services/reminders'; | } from '@features/reminders/services/reminders'; | ||||||
| import { CoreReminderDBRecord } from '@features/reminders/services/database/reminders'; | import { CoreReminderDBRecord } from '@features/reminders/services/database/reminders'; | ||||||
|  | import { CoreEvents } from '@singletons/events'; | ||||||
| 
 | 
 | ||||||
| const ROOT_CACHE_KEY = 'mmaCalendar:'; | const ROOT_CACHE_KEY = 'mmaCalendar:'; | ||||||
| 
 | 
 | ||||||
| @ -297,6 +298,14 @@ export class AddonCalendarProvider { | |||||||
|                 this.notificationClicked(notification); |                 this.notificationClicked(notification); | ||||||
|             }, |             }, | ||||||
|         ); |         ); | ||||||
|  | 
 | ||||||
|  |         CoreEvents.on(CoreEvents.SITE_ADDED, (data) => { | ||||||
|  |             if (!data.siteId) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             this.updateSiteEventReminders(data.siteId); | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -1381,28 +1390,32 @@ export class AddonCalendarProvider { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get the next events for all the sites and schedules their notifications. |      * Get the next events for all the sites and updates their reminders. | ||||||
|      * If an event notification time is 0, cancel its scheduled notification (if any). |  | ||||||
|      * If local notification plugin is not enabled, resolve the promise. |  | ||||||
|      * |  | ||||||
|      * @returns Promise resolved when all the notifications have been scheduled. |  | ||||||
|      */ |      */ | ||||||
|     async updateAllSitesEventReminders(): Promise<void> { |     async updateAllSitesEventReminders(): Promise<void> { | ||||||
|         await CorePlatform.ready(); |         await CorePlatform.ready(); | ||||||
| 
 | 
 | ||||||
|         const siteIds = await CoreSites.getSitesIds(); |         const siteIds = await CoreSites.getSitesIds(); | ||||||
| 
 | 
 | ||||||
|         await Promise.all(siteIds.map(async (siteId) => { |         await Promise.all(siteIds.map(siteId => this.updateSiteEventReminders(siteId))); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the next events for a site and updates their reminders. | ||||||
|  |      * | ||||||
|  |      * @param siteId Site ID. | ||||||
|  |      */ | ||||||
|  |     async updateSiteEventReminders(siteId: string): Promise<void> { | ||||||
|         // Check if calendar is disabled for the site.
 |         // Check if calendar is disabled for the site.
 | ||||||
|         const disabled = await this.isDisabled(siteId); |         const disabled = await this.isDisabled(siteId); | ||||||
|             if (!disabled) { |         if (disabled) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         // Get first events.
 |         // Get first events.
 | ||||||
|         const events = await this.getEventsList(undefined, undefined, undefined, siteId); |         const events = await this.getEventsList(undefined, undefined, undefined, siteId); | ||||||
|         await this.updateEventsReminders(events, siteId); |         await this.updateEventsReminders(events, siteId); | ||||||
|     } |     } | ||||||
|         })); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get the next events for all the sites and schedules their notifications. |      * Get the next events for all the sites and schedules their notifications. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user