MOBILE-4317 calendar: Store events from getEventsList in DB
This schedules their default reminder if it's a new eventmain
parent
d1f28f43ab
commit
99a2d47e30
|
@ -658,8 +658,7 @@ export class AddonCalendarProvider {
|
|||
const response: AddonCalendarGetCalendarEventByIdWSResponse =
|
||||
await site.read('core_calendar_get_calendar_event_by_id', params, preSets);
|
||||
|
||||
this.storeEventInLocalDb(response.event, { siteId });
|
||||
this.updateEventsReminders([response.event], site.getId());
|
||||
this.updateLocalEvents([response.event], { siteId });
|
||||
|
||||
return response.event;
|
||||
} catch (error) {
|
||||
|
@ -835,8 +834,7 @@ export class AddonCalendarProvider {
|
|||
preSets.emergencyCache = false;
|
||||
}
|
||||
const response: AddonCalendarCalendarDay = await site.read('core_calendar_get_calendar_day_view', params, preSets);
|
||||
this.storeEventsInLocalDB(response.events, { siteId });
|
||||
this.updateEventsReminders(response.events, site.getId());
|
||||
this.updateLocalEvents(response.events, { siteId });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
@ -958,8 +956,10 @@ export class AddonCalendarProvider {
|
|||
uniqueCacheKey: true,
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
};
|
||||
const response: AddonCalendarGetCalendarEventsWSResponse =
|
||||
await site.read('core_calendar_get_calendar_events', params, preSets);
|
||||
const response =
|
||||
await site.read<AddonCalendarGetCalendarEventsWSResponse>('core_calendar_get_calendar_events', params, preSets);
|
||||
|
||||
this.updateLocalEvents(response.events, { siteId });
|
||||
|
||||
return response.events;
|
||||
}
|
||||
|
@ -1042,8 +1042,7 @@ export class AddonCalendarProvider {
|
|||
const response = await site.read<AddonCalendarMonth>('core_calendar_get_calendar_monthly_view', params, preSets);
|
||||
response.weeks.forEach((week) => {
|
||||
week.days.forEach((day) => {
|
||||
this.storeEventsInLocalDB(day.events, { siteId });
|
||||
this.updateEventsReminders(day.events, site.getId());
|
||||
this.updateLocalEvents(day.events, { siteId });
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1140,8 +1139,7 @@ export class AddonCalendarProvider {
|
|||
}
|
||||
|
||||
const response = await site.read<AddonCalendarUpcoming>('core_calendar_get_calendar_upcoming_view', params, preSets);
|
||||
this.storeEventsInLocalDB(response.events, { siteId });
|
||||
this.updateEventsReminders(response.events, site.getId());
|
||||
this.updateLocalEvents(response.events, { siteId });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
@ -1412,9 +1410,8 @@ export class AddonCalendarProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
// Get first events.
|
||||
const events = await this.getEventsList(undefined, undefined, undefined, siteId);
|
||||
await this.updateEventsReminders(events, siteId);
|
||||
// Get first events to store/update them in local database and update their reminders.
|
||||
await this.getEventsList(undefined, undefined, undefined, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1600,6 +1597,22 @@ export class AddonCalendarProvider {
|
|||
await Promise.all(events.map((event) => this.storeEventInLocalDb(event, options)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update local events, storing them in DB and also updating their reminders.
|
||||
*
|
||||
* @param events Events to store or update.
|
||||
* @param options Options.
|
||||
*/
|
||||
protected async updateLocalEvents(
|
||||
events: (AddonCalendarGetEventsEvent | AddonCalendarCalendarEvent | AddonCalendarEvent)[],
|
||||
options: AddonCalendarStoreEventsOptions = {},
|
||||
): Promise<void> {
|
||||
options.siteId = options.siteId || CoreSites.getCurrentSiteId();
|
||||
|
||||
await this.storeEventsInLocalDB(events, options);
|
||||
await this.updateEventsReminders(events, options.siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a calendar event.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue