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,6 +116,7 @@ describe('TimelineSpace/Contents/Home', () => {
describe('appendTimeline', () => { describe('appendTimeline', () => {
describe('heading', () => { describe('heading', () => {
describe('normal', () => {
beforeEach(() => { beforeEach(() => {
state = { state = {
lazyLoading: false, lazyLoading: false,
@ -134,7 +135,28 @@ describe('TimelineSpace/Contents/Home', () => {
}) })
}) })
describe('duplicated status', () => {
beforeEach(() => {
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', () => {
describe('normal', () => {
beforeEach(() => { beforeEach(() => {
state = { state = {
lazyLoading: false, lazyLoading: false,
@ -152,6 +174,25 @@ describe('TimelineSpace/Contents/Home', () => {
expect(state.unreadTimeline).toEqual([status2]) expect(state.unreadTimeline).toEqual([status2])
}) })
}) })
describe('duplicated status', () => {
beforeEach(() => {
state = {
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])
})
})
})
}) })
describe('mergeTimeline', () => { describe('mergeTimeline', () => {

View File

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