MOBILE-3320 user: Make preferences fail-safe
parent
70d14de8ec
commit
c1e2acf98a
|
@ -566,14 +566,14 @@ export class AddonCalendarProvider {
|
||||||
*/
|
*/
|
||||||
async getCalendarLookAhead(siteId?: string): Promise<number> {
|
async getCalendarLookAhead(siteId?: string): Promise<number> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
let value: string | undefined;
|
let value: string | undefined | null;
|
||||||
try {
|
try {
|
||||||
value = await CoreUser.getUserPreference('calendar_lookahead');
|
value = await CoreUser.getUserPreference('calendar_lookahead');
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value == 'undefined') {
|
if (typeof value == 'undefined' || value === null) {
|
||||||
value = site.getStoredConfig('calendar_lookahead');
|
value = site.getStoredConfig('calendar_lookahead');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ export class AddonCalendarProvider {
|
||||||
*/
|
*/
|
||||||
async getCalendarTimeFormat(siteId?: string): Promise<string> {
|
async getCalendarTimeFormat(siteId?: string): Promise<string> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
let format: string | undefined;
|
let format: string | undefined | null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
format = await CoreUser.getUserPreference('calendar_timeformat');
|
format = await CoreUser.getUserPreference('calendar_timeformat');
|
||||||
|
|
|
@ -391,7 +391,7 @@ export class CoreUserProvider {
|
||||||
* @param siteId Site Id. If not defined, use current site.
|
* @param siteId Site Id. If not defined, use current site.
|
||||||
* @return Preference value or null if preference not set.
|
* @return Preference value or null if preference not set.
|
||||||
*/
|
*/
|
||||||
async getUserPreference(name: string, siteId?: string): Promise<string> {
|
async getUserPreference(name: string, siteId?: string): Promise<string | null> {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId));
|
const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId));
|
||||||
|
@ -403,20 +403,15 @@ export class CoreUserProvider {
|
||||||
|
|
||||||
const wsValue = await this.getUserPreferenceOnline(name, siteId);
|
const wsValue = await this.getUserPreferenceOnline(name, siteId);
|
||||||
|
|
||||||
if (!wsValue) {
|
|
||||||
if (preference) {
|
|
||||||
// Return the local value.
|
|
||||||
return preference.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new CoreError('Preference not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preference && preference.value != preference.onlinevalue && preference.onlinevalue == wsValue) {
|
if (preference && preference.value != preference.onlinevalue && preference.onlinevalue == wsValue) {
|
||||||
// Sync is pending for this preference, return stored value.
|
// Sync is pending for this preference, return stored value.
|
||||||
return preference.value;
|
return preference.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wsValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
await CoreUserOffline.setPreference(name, wsValue, wsValue);
|
await CoreUserOffline.setPreference(name, wsValue, wsValue);
|
||||||
|
|
||||||
return wsValue;
|
return wsValue;
|
||||||
|
|
Loading…
Reference in New Issue