Merge pull request #3634 from dpalou/MOBILE-4317
MOBILE-4317 calendar: Store events from getEventsList in DBmain
commit
6cb78cf27e
|
@ -658,8 +658,7 @@ export class AddonCalendarProvider {
|
||||||
const response: AddonCalendarGetCalendarEventByIdWSResponse =
|
const response: AddonCalendarGetCalendarEventByIdWSResponse =
|
||||||
await site.read('core_calendar_get_calendar_event_by_id', params, preSets);
|
await site.read('core_calendar_get_calendar_event_by_id', params, preSets);
|
||||||
|
|
||||||
this.storeEventInLocalDb(response.event, { siteId });
|
this.updateLocalEvents([response.event], { siteId });
|
||||||
this.updateEventsReminders([response.event], site.getId());
|
|
||||||
|
|
||||||
return response.event;
|
return response.event;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -835,8 +834,7 @@ export class AddonCalendarProvider {
|
||||||
preSets.emergencyCache = false;
|
preSets.emergencyCache = false;
|
||||||
}
|
}
|
||||||
const response: AddonCalendarCalendarDay = await site.read('core_calendar_get_calendar_day_view', params, preSets);
|
const response: AddonCalendarCalendarDay = await site.read('core_calendar_get_calendar_day_view', params, preSets);
|
||||||
this.storeEventsInLocalDB(response.events, { siteId });
|
this.updateLocalEvents(response.events, { siteId });
|
||||||
this.updateEventsReminders(response.events, site.getId());
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -958,8 +956,10 @@ export class AddonCalendarProvider {
|
||||||
uniqueCacheKey: true,
|
uniqueCacheKey: true,
|
||||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||||
};
|
};
|
||||||
const response: AddonCalendarGetCalendarEventsWSResponse =
|
const response =
|
||||||
await site.read('core_calendar_get_calendar_events', params, preSets);
|
await site.read<AddonCalendarGetCalendarEventsWSResponse>('core_calendar_get_calendar_events', params, preSets);
|
||||||
|
|
||||||
|
this.updateLocalEvents(response.events, { siteId });
|
||||||
|
|
||||||
return response.events;
|
return response.events;
|
||||||
}
|
}
|
||||||
|
@ -1042,8 +1042,7 @@ export class AddonCalendarProvider {
|
||||||
const response = await site.read<AddonCalendarMonth>('core_calendar_get_calendar_monthly_view', params, preSets);
|
const response = await site.read<AddonCalendarMonth>('core_calendar_get_calendar_monthly_view', params, preSets);
|
||||||
response.weeks.forEach((week) => {
|
response.weeks.forEach((week) => {
|
||||||
week.days.forEach((day) => {
|
week.days.forEach((day) => {
|
||||||
this.storeEventsInLocalDB(day.events, { siteId });
|
this.updateLocalEvents(day.events, { siteId });
|
||||||
this.updateEventsReminders(day.events, site.getId());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1140,8 +1139,7 @@ export class AddonCalendarProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await site.read<AddonCalendarUpcoming>('core_calendar_get_calendar_upcoming_view', params, preSets);
|
const response = await site.read<AddonCalendarUpcoming>('core_calendar_get_calendar_upcoming_view', params, preSets);
|
||||||
this.storeEventsInLocalDB(response.events, { siteId });
|
this.updateLocalEvents(response.events, { siteId });
|
||||||
this.updateEventsReminders(response.events, site.getId());
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -1412,9 +1410,8 @@ export class AddonCalendarProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get first events.
|
// Get first events to store/update them in local database and update their reminders.
|
||||||
const events = await this.getEventsList(undefined, undefined, undefined, siteId);
|
await this.getEventsList(undefined, undefined, undefined, siteId);
|
||||||
await this.updateEventsReminders(events, siteId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1600,6 +1597,22 @@ export class AddonCalendarProvider {
|
||||||
await Promise.all(events.map((event) => this.storeEventInLocalDb(event, options)));
|
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.
|
* Submit a calendar event.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue