refs #1096 Reject duplicated status when append statuses in Home

This commit is contained in:
AkiraFukushima 2019-11-13 22:53:38 +09:00
parent 65d0bb622e
commit 6f4c90a2cf
2 changed files with 76 additions and 32 deletions

View File

@ -116,40 +116,81 @@ describe('TimelineSpace/Contents/Home', () => {
describe('appendTimeline', () => { describe('appendTimeline', () => {
describe('heading', () => { describe('heading', () => {
beforeEach(() => { describe('normal', () => {
state = { beforeEach(() => {
lazyLoading: false, state = {
heading: true, lazyLoading: false,
timeline: [status1], heading: true,
unreadTimeline: [], timeline: [status1],
filter: '', unreadTimeline: [],
showReblogs: true, filter: '',
showReplies: true showReblogs: true,
} showReplies: true
}
})
it('should update timeline', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2)
expect(state.timeline).toEqual([status2, status1])
expect(state.unreadTimeline).toEqual([])
})
}) })
it('should update timeline', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) describe('duplicated status', () => {
expect(state.timeline).toEqual([status2, status1]) beforeEach(() => {
expect(state.unreadTimeline).toEqual([]) state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
})
it('should not update timeline', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2)
expect(state.timeline).toEqual([status2, status1])
expect(state.unreadTimeline).toEqual([])
})
}) })
}) })
describe('not heading', () => { describe('not heading', () => {
beforeEach(() => { describe('normal', () => {
state = { beforeEach(() => {
lazyLoading: false, state = {
heading: false, lazyLoading: false,
timeline: [status1], heading: false,
unreadTimeline: [], timeline: [status1],
filter: '', unreadTimeline: [],
showReblogs: true, filter: '',
showReplies: true showReblogs: true,
} showReplies: true
}
})
it('should update unreadTimeline', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2)
expect(state.timeline).toEqual([status1])
expect(state.unreadTimeline).toEqual([status2])
})
}) })
it('should update unreadTimeline', () => { describe('duplicated status', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) beforeEach(() => {
expect(state.timeline).toEqual([status1]) state = {
expect(state.unreadTimeline).toEqual([status2]) lazyLoading: false,
heading: false,
timeline: [],
unreadTimeline: [status2, status1],
filter: '',
showReblogs: true,
showReplies: true
}
})
it('should not update unreadTimeline', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2)
expect(state.timeline).toEqual([])
expect(state.unreadTimeline).toEqual([status2, status1])
})
}) })
}) })
}) })

View File

@ -46,10 +46,13 @@ const mutations: MutationTree<HomeState> = {
state.heading = value state.heading = value
}, },
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => {
if (state.heading) { // Reject duplicated status in timeline
state.timeline = [update].concat(state.timeline) if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
} else { if (state.heading) {
state.unreadTimeline = [update].concat(state.unreadTimeline) state.timeline = [update].concat(state.timeline)
} else {
state.unreadTimeline = [update].concat(state.unreadTimeline)
}
} }
}, },
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => { [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => {