MOBILE-4081 user: Fix offline preference not synchronized
parent
6a11ea5d55
commit
efca5aa61c
|
@ -15,6 +15,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { PREFERENCES_TABLE_NAME, CoreUserPreferenceDBRecord } from './database/user';
|
import { PREFERENCES_TABLE_NAME, CoreUserPreferenceDBRecord } from './database/user';
|
||||||
|
|
||||||
|
@ -33,7 +34,10 @@ export class CoreUserOfflineProvider {
|
||||||
async getChangedPreferences(siteId?: string): Promise<CoreUserPreferenceDBRecord[]> {
|
async getChangedPreferences(siteId?: string): Promise<CoreUserPreferenceDBRecord[]> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
||||||
return site.getDb().getRecordsSelect(PREFERENCES_TABLE_NAME, 'value != onlineValue');
|
return site.getDb().getRecordsSelect(
|
||||||
|
PREFERENCES_TABLE_NAME,
|
||||||
|
'value != onlinevalue OR onlinevalue IS NULL',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,8 +68,19 @@ export class CoreUserOfflineProvider {
|
||||||
const record: Partial<CoreUserPreferenceDBRecord> = {
|
const record: Partial<CoreUserPreferenceDBRecord> = {
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
|
onlinevalue: onlineValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (onlineValue === undefined) {
|
||||||
|
// Keep online value already stored (if any).
|
||||||
|
const entry = await CoreUtils.ignoreErrors(
|
||||||
|
site.getDb().getRecord<CoreUserPreferenceDBRecord>(PREFERENCES_TABLE_NAME, { name }),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
record.onlinevalue = entry?.onlinevalue;
|
||||||
|
}
|
||||||
|
|
||||||
await site.getDb().insertRecord(PREFERENCES_TABLE_NAME, record);
|
await site.getDb().insertRecord(PREFERENCES_TABLE_NAME, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue