diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts index 84969ad3..800c9ec4 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts @@ -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]) + }) }) }) }) diff --git a/src/renderer/store/TimelineSpace/Contents/Home.ts b/src/renderer/store/TimelineSpace/Contents/Home.ts index f2326d7d..5518ab54 100644 --- a/src/renderer/store/TimelineSpace/Contents/Home.ts +++ b/src/renderer/store/TimelineSpace/Contents/Home.ts @@ -46,10 +46,13 @@ const mutations: MutationTree = { 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) => {