fixes, clear cache on logout

This commit is contained in:
Henry Jameson 2022-08-12 01:19:19 +03:00
parent c3e7eadddf
commit 8d3d8fffab
7 changed files with 20 additions and 8 deletions

View File

@ -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
}
)

View File

@ -16,6 +16,7 @@ const NavigationEntry = {
} else {
this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value })
}
this.$store.dispatch('pushServerSideStorage')
}
},
computed: {

View File

@ -64,7 +64,7 @@ const NavPanel = {
{
hasChats: this.pleromaChatMessagesAvailable,
isFederating: this.federating,
isPrivate: this.private,
isPrivate: this.privateMode,
currentUser: this.currentUser
}
)

View File

@ -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 })

View File

@ -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) {

View File

@ -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

View File

@ -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({