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('heading', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: '',
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)
expect(state.timeline).toEqual([status2, status1])
expect(state.unreadTimeline).toEqual([])
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', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
timeline: [status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
timeline: [status1],
unreadTimeline: [],
filter: '',
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', () => {
Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2)
expect(state.timeline).toEqual([status1])
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])
})
})
})
})

View File

@ -46,10 +46,13 @@ const mutations: MutationTree<HomeState> = {
state.heading = value
},
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => {
if (state.heading) {
state.timeline = [update].concat(state.timeline)
} else {
state.unreadTimeline = [update].concat(state.unreadTimeline)
// 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) {
state.timeline = [update].concat(state.timeline)
} else {
state.unreadTimeline = [update].concat(state.unreadTimeline)
}
}
},
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => {