Merge branch 'issue-392-other-user-stale-data' into 'develop'

#392: stale data served to new user account

Closes #392

See merge request pleroma/pleroma-fe!625
This commit is contained in:
Shpuld Shpludson 2019-03-07 16:33:22 +00:00
commit 09b0f6dd87
4 changed files with 37 additions and 19 deletions

View File

@ -11,7 +11,8 @@ const Notifications = {
const store = this.$store
const credentials = store.state.users.currentUser.credentials
notificationsFetcher.startFetching({ store, credentials })
const fetcherId = notificationsFetcher.startFetching({ store, credentials })
this.$store.commit('setNotificationFetcher', { fetcherId })
},
data () {
return {

View File

@ -19,7 +19,7 @@ const emptyTl = (userId = 0) => ({
flushMarker: 0
})
export const defaultState = {
export const defaultState = () => ({
allStatuses: [],
allStatusesObject: {},
maxId: 0,
@ -30,7 +30,8 @@ export const defaultState = {
data: [],
idStore: {},
loading: false,
error: false
error: false,
fetcherId: null
},
favorites: new Set(),
error: false,
@ -45,7 +46,7 @@ export const defaultState = {
tag: emptyTl(),
dms: emptyTl()
}
}
})
export const prepareStatus = (status) => {
// Set deleted flag
@ -335,6 +336,15 @@ export const mutations = {
oldTimeline.visibleStatusesObject = {}
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
},
setNotificationFetcher (state, { fetcherId }) {
state.notifications.fetcherId = fetcherId
},
resetStatuses (state) {
const emptyState = defaultState()
Object.entries(emptyState).forEach(([key, value]) => {
state[key] = value
})
},
clearTimeline (state, { timeline }) {
state.timelines[timeline] = emptyTl(state.timelines[timeline].userId)
},
@ -385,7 +395,7 @@ export const mutations = {
}
const statuses = {
state: defaultState,
state: defaultState(),
actions: {
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId }) {
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId })
@ -405,6 +415,12 @@ const statuses = {
setNotificationsSilence ({ rootState, commit }, { value }) {
commit('setNotificationsSilence', { value })
},
stopFetchingNotifications ({ rootState, commit }) {
if (rootState.statuses.notifications.fetcherId) {
window.clearInterval(rootState.statuses.notifications.fetcherId)
}
commit('setNotificationFetcher', { fetcherId: null })
},
deleteStatus ({ rootState, commit }, status) {
commit('setDeleted', { status })
apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials })

View File

@ -295,6 +295,8 @@ const users = {
store.commit('setToken', false)
store.dispatch('stopFetching', 'friends')
store.commit('setBackendInteractor', backendInteractorService())
store.dispatch('stopFetchingNotifications')
store.commit('resetStatuses')
},
loginUser (store, accessToken) {
return new Promise((resolve, reject) => {

View File

@ -1,4 +1,3 @@
import { cloneDeep } from 'lodash'
import { defaultState, mutations, prepareStatus } from '../../../../src/modules/statuses.js'
// eslint-disable-next-line camelcase
@ -24,7 +23,7 @@ describe('Statuses.prepareStatus', () => {
describe('The Statuses module', () => {
it('adds the status to allStatuses and to the given timeline', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
mutations.addNewStatuses(state, { statuses: [status], timeline: 'public' })
@ -36,7 +35,7 @@ describe('The Statuses module', () => {
})
it('counts the status as new if it has not been seen on this timeline', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
mutations.addNewStatuses(state, { statuses: [status], timeline: 'public' })
@ -54,7 +53,7 @@ describe('The Statuses module', () => {
})
it('add the statuses to allStatuses if no timeline is given', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
mutations.addNewStatuses(state, { statuses: [status] })
@ -66,7 +65,7 @@ describe('The Statuses module', () => {
})
it('adds the status to allStatuses and to the given timeline, directly visible', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' })
@ -78,7 +77,7 @@ describe('The Statuses module', () => {
})
it('removes statuses by tag on deletion', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const otherStatus = makeMockStatus({id: '3'})
status.uri = 'xxx'
@ -96,7 +95,7 @@ describe('The Statuses module', () => {
})
it('does not update the maxId when the noIdUpdate flag is set', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const secondStatus = makeMockStatus({id: '2'})
@ -110,7 +109,7 @@ describe('The Statuses module', () => {
})
it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const nonVisibleStatus = makeMockStatus({id: '1'})
const status = makeMockStatus({id: '3'})
const statusTwo = makeMockStatus({id: '2'})
@ -130,7 +129,7 @@ describe('The Statuses module', () => {
})
it('splits retweets from their status and links them', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const retweet = makeMockStatus({id: '2', type: 'retweet'})
const modStatus = makeMockStatus({id: '1', text: 'something else'})
@ -155,7 +154,7 @@ describe('The Statuses module', () => {
})
it('replaces existing statuses with the same id', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const modStatus = makeMockStatus({id: '1', text: 'something else'})
@ -172,7 +171,7 @@ describe('The Statuses module', () => {
})
it('replaces existing statuses with the same id, coming from a retweet', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const modStatus = makeMockStatus({id: '1', text: 'something else'})
const retweet = makeMockStatus({id: '2', type: 'retweet'})
@ -193,7 +192,7 @@ describe('The Statuses module', () => {
})
it('handles favorite actions', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const favorite = {
@ -241,7 +240,7 @@ describe('The Statuses module', () => {
})
it('keeps userId when clearing user timeline', () => {
const state = cloneDeep(defaultState)
const state = defaultState()
state.timelines.user.userId = 123
mutations.clearTimeline(state, { timeline: 'user' })
@ -252,7 +251,7 @@ describe('The Statuses module', () => {
describe('notifications', () => {
it('removes a notification when the notice gets removed', () => {
const user = { id: '1' }
const state = cloneDeep(defaultState)
const state = defaultState()
const status = makeMockStatus({id: '1'})
const otherStatus = makeMockStatus({id: '3'})
const mentionedStatus = makeMockStatus({id: '2'})