diff --git a/src/components/settings_modal/tabs/filtering_tab.js b/src/components/settings_modal/tabs/filtering_tab.js index facc6073f..04dfe76bd 100644 --- a/src/components/settings_modal/tabs/filtering_tab.js +++ b/src/components/settings_modal/tabs/filtering_tab.js @@ -36,11 +36,11 @@ const FilteringTab = { label: this.$t(`user_card.mute_block_${mode}`), })), muteFiltersDraftObject: cloneDeep( - useSyncConfigStore().prefsStorage.simple.muteFilters, + this.prefsStorage.simple.muteFilters, ), muteFiltersDraftDirty: Object.fromEntries( Object.entries( - useSyncConfigStore().prefsStorage.simple.muteFilters, + this.prefsStorage.simple.muteFilters, ).map(([k]) => [k, false]), ), exportedFilter: null, diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js index 99ff0f6d5..c87e0bece 100644 --- a/src/stores/sync_config.js +++ b/src/stores/sync_config.js @@ -159,6 +159,13 @@ export const _getRecentData = (cache, live, isTest) => { } const merge = (a, b) => { + console.log( + 'MERGE', + a.prefsStorage.simple.conversationDisplay, + b.prefsStorage.simple.conversationDisplay, + ) + console.log(a.prefsStorage.simple) + console.log(cloneDeep(a.prefsStorage).simple) return { _user: a._user ?? b._user, _version: a._version ?? b._version, @@ -169,14 +176,18 @@ export const _getRecentData = (cache, live, isTest) => { } } + console.log('1',result.recent.prefsStorage.simple.conversationDisplay) + result.recent = isTest ? result.recent : result.recent && merge(defaultState, result.recent) + console.log('2',result.recent.prefsStorage.simple.conversationDisplay) result.stale = isTest ? result.stale : result.stale && merge(defaultState, result.stale) + console.log('3', result.recent.prefsStorage.simple.conversationDisplay) return result } @@ -586,7 +597,21 @@ export const useSyncConfigStore = defineStore('sync_config', { cache = null } + console.log('======') + console.log('CACHE', cache?.prefsStorage?.simple?.conversationDisplay) + console.log('LIVE', live?.prefsStorage?.simple?.conversationDisplay) + if (cache?._timestamp > live?._timestamp) { + console.log('C > L') + } else if (cache?._timestamp === live?._timestamp) { + console.log('C = L') + } else { + console.log('C < L') + } let { recent, stale, needUpload } = _getRecentData(cache, live) + console.log('======') + console.log('RECENT', recent.prefsStorage?.simple?.conversationDisplay) + console.log('STALE', stale?.prefsStorage?.simple?.conversationDisplay) + console.log('======') const userNew = userData.created_at > NEW_USER_DATE const flagsTemplate = userNew ? newUserFlags : defaultState.flagStorage diff --git a/test/unit/specs/stores/sync_config.spec.js b/test/unit/specs/stores/sync_config.spec.js index 561f6dcbb..abcddbeb1 100644 --- a/test/unit/specs/stores/sync_config.spec.js +++ b/test/unit/specs/stores/sync_config.spec.js @@ -123,14 +123,30 @@ describe('The SyncConfig module', () => { store.setPreference({ path: 'simple.testing', value: 1 }) store.setPreference({ path: 'simple.testing', value: 2 }) store.addCollectionPreference({ path: 'collections.testing', value: 2 }) + store.addCollectionPreference({ + path: 'objectCollections.testing', + value: { _key: 'a', foo: 1 }, + }) + expect(store.prefsStorage.objectCollections.testing).to.eql({ + data: { a: { _key: 'a', foo: 1 } }, + index: ['a'], + }) store.removeCollectionPreference({ path: 'collections.testing', value: 2, }) + store.removeCollectionPreference({ + path: 'objectCollections.testing', + value: { _key: 'a' }, + }) store.updateCache({ username: 'test' }) expect(store.prefsStorage.simple.testing).to.eql(2) expect(store.prefsStorage.collections.testing).to.eql([]) - expect(store.prefsStorage._journal.length).to.eql(2) + expect(store.prefsStorage.objectCollections.testing).to.eql({ + data: {}, + index: [], + }) + expect(store.prefsStorage._journal.length).to.eql(3) expect(store.prefsStorage._journal[0]).to.eql({ path: 'simple.testing', operation: 'set', @@ -145,6 +161,13 @@ describe('The SyncConfig module', () => { // should have A timestamp, we don't really care what it is timestamp: store.prefsStorage._journal[1].timestamp, }) + expect(store.prefsStorage._journal[2]).to.eql({ + path: 'objectCollections.testing', + operation: 'removeFromCollection', + args: [{ _key: 'a' }], + // should have A timestamp, we don't really care what it is + timestamp: store.prefsStorage._journal[2].timestamp, + }) }) it('should remove duplicate entries from journal', () => { @@ -153,10 +176,22 @@ describe('The SyncConfig module', () => { store.setPreference({ path: 'simple.testing', value: 1 }) store.addCollectionPreference({ path: 'collections.testing', value: 2 }) store.addCollectionPreference({ path: 'collections.testing', value: 2 }) + store.addCollectionPreference({ + path: 'objectCollections.testing', + value: { _key: 'a', foo: 1 }, + }) + store.addCollectionPreference({ + path: 'objectCollections.testing', + value: { _key: 'a', foo: 1 }, + }) store.updateCache({ username: 'test' }) expect(store.prefsStorage.simple.testing).to.eql(1) expect(store.prefsStorage.collections.testing).to.eql([2]) - expect(store.prefsStorage._journal.length).to.eql(2) + expect(store.prefsStorage.objectCollections.testing).to.eql({ + data: { a: { _key: 'a', foo: 1 } }, + index: ['a'], + }) + expect(store.prefsStorage._journal.length).to.eql(4) }) it('should remove depth = 3 set/unset entries from journal', () => {