From efca5aa61c1cd2d4850b6d8f3fe8388e131ae16c Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 13 Dec 2022 08:09:20 +0100 Subject: [PATCH] MOBILE-4081 user: Fix offline preference not synchronized --- src/core/features/user/services/user-offline.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/features/user/services/user-offline.ts b/src/core/features/user/services/user-offline.ts index 8d10efa46..09d060685 100644 --- a/src/core/features/user/services/user-offline.ts +++ b/src/core/features/user/services/user-offline.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; +import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { PREFERENCES_TABLE_NAME, CoreUserPreferenceDBRecord } from './database/user'; @@ -33,7 +34,10 @@ export class CoreUserOfflineProvider { async getChangedPreferences(siteId?: string): Promise { 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 = { name, value, + onlinevalue: onlineValue, }; + if (onlineValue === undefined) { + // Keep online value already stored (if any). + const entry = await CoreUtils.ignoreErrors( + site.getDb().getRecord(PREFERENCES_TABLE_NAME, { name }), + null, + ); + + record.onlinevalue = entry?.onlinevalue; + } + await site.getDb().insertRecord(PREFERENCES_TABLE_NAME, record); }