From a776e378527113336e2d78c6b007d6a72d6dbad3 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 1 Feb 2022 08:14:08 +0100 Subject: [PATCH] MOBILE-3975 calendar: Move default reminder initial value to config --- moodle.config.json | 3 ++- src/addons/calendar/services/calendar.ts | 3 +-- src/addons/calendar/services/database/calendar.ts | 11 ++++++++--- src/types/config.d.ts | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/moodle.config.json b/moodle.config.json index 84a52ba65..374012c07 100644 --- a/moodle.config.json +++ b/moodle.config.json @@ -101,5 +101,6 @@ "ios": "id633359593" }, "wsrequestqueuelimit": 10, - "wsrequestqueuedelay": 100 + "wsrequestqueuedelay": 100, + "calendarreminderdefaultvalue": 3600 } diff --git a/src/addons/calendar/services/calendar.ts b/src/addons/calendar/services/calendar.ts index 6ec1cbc0e..ec8c8db11 100644 --- a/src/addons/calendar/services/calendar.ts +++ b/src/addons/calendar/services/calendar.ts @@ -108,7 +108,6 @@ export class AddonCalendarProvider { static readonly COMPONENT = 'AddonCalendarEvents'; static readonly DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent'; static readonly DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime'; - static readonly DEFAULT_NOTIFICATION_TIME = 3600; static readonly STARTING_WEEK_DAY = 'addon_calendar_starting_week_day'; static readonly NEW_EVENT_EVENT = 'addon_calendar_new_event'; static readonly NEW_EVENT_DISCARDED_EVENT = 'addon_calendar_new_event_discarded'; @@ -638,7 +637,7 @@ export class AddonCalendarProvider { const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; - return CoreConfig.get(key, AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME); + return CoreConfig.get(key, CoreConstants.CONFIG.calendarreminderdefaultvalue || 3600); } /** diff --git a/src/addons/calendar/services/database/calendar.ts b/src/addons/calendar/services/database/calendar.ts index c7591fa5c..6c6be2fd7 100644 --- a/src/addons/calendar/services/database/calendar.ts +++ b/src/addons/calendar/services/database/calendar.ts @@ -13,9 +13,10 @@ // limitations under the License. import { SQLiteDB } from '@classes/sqlitedb'; +import { CoreConfig } from '@services/config'; import { CoreSiteSchema } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { AddonCalendar, AddonCalendarEventType } from '../calendar'; +import { AddonCalendar, AddonCalendarEventType, AddonCalendarProvider } from '../calendar'; /** * Database variables for AddonDatabase service. @@ -216,13 +217,17 @@ export const CALENDAR_SITE_SCHEMA: CoreSiteSchema = { } if (oldVersion < 4) { - // Migrate reminders. New format @since 4.0. - const defaultTime = await CoreUtils.ignoreErrors(AddonCalendar.getDefaultNotificationTime(siteId)); + // Migrate default notification time if it was changed. + // Don't use getDefaultNotificationTime to be able to detect if the value was changed or not. + const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; + const defaultTime = await CoreUtils.ignoreErrors(CoreConfig.get(key, null)); + if (defaultTime) { // Convert from minutes to seconds. AddonCalendar.setDefaultNotificationTime(defaultTime * 60, siteId); } + // Migrate reminders. New format @since 4.0. const records = await db.getAllRecords(REMINDERS_TABLE); const events: Record = {}; diff --git a/src/types/config.d.ts b/src/types/config.d.ts index c5df37dcd..ccbac9336 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -60,4 +60,5 @@ export interface EnvironmentConfig { iabToolbarColors?: 'auto' | { background: string; text?: string } | null; wsrequestqueuelimit: number; // Maximum number of requests allowed in the queue. wsrequestqueuedelay: number; // Maximum number of miliseconds to wait before processing the queue. + calendarreminderdefaultvalue: number; // Initial value for default reminders (in seconds). User can change it later. }