From 8d3d8fffab0106a8aff5822044a8c3c30bd6e057 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 12 Aug 2022 01:19:19 +0300 Subject: [PATCH] fixes, clear cache on logout --- src/components/nav_panel/nav_panel.js | 4 ++-- src/components/navigation/navigation_entry.js | 1 + src/components/navigation/navigation_pins.js | 2 +- src/modules/serverSideStorage.js | 17 +++++++++++++---- src/modules/users.js | 1 + .../entity_normalizer.service.js | 1 + .../specs/modules/serverSideStorage.spec.js | 2 +- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js index 0d71a924..26e8440a 100644 --- a/src/components/nav_panel/nav_panel.js +++ b/src/components/nav_panel/nav_panel.js @@ -95,7 +95,7 @@ const NavPanel = { { hasChats: this.pleromaChatMessagesAvailable, isFederating: this.federating, - isPrivate: this.private, + isPrivate: this.privateMode, currentUser: this.currentUser } ) @@ -108,7 +108,7 @@ const NavPanel = { { hasChats: this.pleromaChatMessagesAvailable, isFederating: this.federating, - isPrivate: this.private, + isPrivate: this.privateMode, currentUser: this.currentUser } ) diff --git a/src/components/navigation/navigation_entry.js b/src/components/navigation/navigation_entry.js index 09c216ed..e17e9436 100644 --- a/src/components/navigation/navigation_entry.js +++ b/src/components/navigation/navigation_entry.js @@ -16,6 +16,7 @@ const NavigationEntry = { } else { this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value }) } + this.$store.dispatch('pushServerSideStorage') } }, computed: { diff --git a/src/components/navigation/navigation_pins.js b/src/components/navigation/navigation_pins.js index 8a892466..43be4275 100644 --- a/src/components/navigation/navigation_pins.js +++ b/src/components/navigation/navigation_pins.js @@ -64,7 +64,7 @@ const NavPanel = { { hasChats: this.pleromaChatMessagesAvailable, isFederating: this.federating, - isPrivate: this.private, + isPrivate: this.privateMode, currentUser: this.currentUser } ) diff --git a/src/modules/serverSideStorage.js b/src/modules/serverSideStorage.js index d95fbb8a..5581783f 100644 --- a/src/modules/serverSideStorage.js +++ b/src/modules/serverSideStorage.js @@ -51,8 +51,9 @@ export const _moveItemInArray = (array, value, movement) => { return newArray } -const _wrapData = (data) => ({ +const _wrapData = (data, userName) => ({ ...data, + _user: userName, _timestamp: Date.now(), _version: VERSION }) @@ -254,10 +255,17 @@ export const _doMigrations = (cache) => { } export const mutations = { + clearServerSideStorage (state, userData) { + state = { ...cloneDeep(defaultState) } + }, setServerSideStorage (state, userData) { const live = userData.storage state.raw = live let cache = state.cache + if (cache._user !== userData.fqn) { + console.warn('cache belongs to another user! reinitializing local cache!') + cache = null + } cache = _doMigrations(cache) @@ -371,12 +379,12 @@ export const mutations = { ] state.dirty = true }, - updateCache (state) { + updateCache (state, { username }) { state.prefsStorage._journal = _mergeJournal(state.prefsStorage._journal) state.cache = _wrapData({ flagStorage: toRaw(state.flagStorage), prefsStorage: toRaw(state.prefsStorage) - }) + }, username) } } @@ -388,8 +396,9 @@ const serverSideStorage = { actions: { pushServerSideStorage ({ state, rootState, commit }, { force = false } = {}) { const needPush = state.dirty || force + console.log(needPush) if (!needPush) return - commit('updateCache') + commit('updateCache', { username: rootState.users.currentUser.fqn }) const params = { pleroma_settings_store: { 'pleroma-fe': state.cache } } rootState.api.backendInteractor .updateProfile({ params }) diff --git a/src/modules/users.js b/src/modules/users.js index b6fb9746..fe92d697 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -509,6 +509,7 @@ const users = { store.dispatch('setLastTimeline', 'public-timeline') store.dispatch('setLayoutWidth', windowWidth()) store.dispatch('setLayoutHeight', windowHeight()) + store.commit('clearServerSideStorage') }) }, loginUser (store, accessToken) { diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index e9cbcfe6..b1ad2691 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -48,6 +48,7 @@ export const parseUser = (data) => { if (masto) { output.screen_name = data.acct + output.fqn = data.fqn output.statusnet_profile_url = data.url // There's nothing else to get diff --git a/test/unit/specs/modules/serverSideStorage.spec.js b/test/unit/specs/modules/serverSideStorage.spec.js index edb23e8a..f10e21e6 100644 --- a/test/unit/specs/modules/serverSideStorage.spec.js +++ b/test/unit/specs/modules/serverSideStorage.spec.js @@ -127,7 +127,7 @@ describe('The serverSideStorage module', () => { const state = cloneDeep(defaultState) setPreference(state, { path: 'simple.testing', value: 1 }) setPreference(state, { path: 'simple.testing', value: 2 }) - updateCache(state) + updateCache(state, { username: 'test' }) expect(state.prefsStorage.simple.testing).to.eql(2) expect(state.prefsStorage._journal.length).to.eql(1) expect(state.prefsStorage._journal[0]).to.eql({