From e892fffda797c4d5e6aef54a488f15f55526a29d Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 16 Feb 2017 12:51:24 +0100 Subject: [PATCH] Correctly calculate the newStatusesCount. Fixes a bug when viewing an updating twkn while logged in. --- src/modules/statuses.js | 6 ++++-- test/unit/specs/modules/statuses.spec.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index b1aa404af1..871172b5bc 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -153,16 +153,18 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } } + // Decide if we should treat the status as new for this timeline. + let resultForCurrentTimeline // Some statuses should only be added to the global status repository. if (timeline && addToTimeline) { - mergeOrAdd(timelineObject.statuses, status) + resultForCurrentTimeline = mergeOrAdd(timelineObject.statuses, status) } if (timeline && showImmediately) { // Add it directly to the visibleStatuses, don't change // newStatusCount mergeOrAdd(timelineObject.visibleStatuses, status) - } else if (timeline && addToTimeline && result.new) { + } else if (timeline && addToTimeline && resultForCurrentTimeline.new) { // Just change newStatuscount timelineObject.newStatusCount += 1 } diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index c130cbf36e..b1581e03e1 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -79,6 +79,24 @@ describe('The Statuses module', () => { expect(state.timelines.public.newStatusCount).to.equal(1) }) + it('counts the status as new if it has not been seen on this timeline', () => { + const state = cloneDeep(defaultState) + const status = makeMockStatus({id: 1}) + + mutations.addNewStatuses(state, { statuses: [status], timeline: 'public' }) + mutations.addNewStatuses(state, { statuses: [status], timeline: 'friends' }) + + expect(state.allStatuses).to.eql([status]) + expect(state.timelines.public.statuses).to.eql([status]) + expect(state.timelines.public.visibleStatuses).to.eql([]) + expect(state.timelines.public.newStatusCount).to.equal(1) + + expect(state.allStatuses).to.eql([status]) + expect(state.timelines.friends.statuses).to.eql([status]) + expect(state.timelines.friends.visibleStatuses).to.eql([]) + expect(state.timelines.friends.newStatusCount).to.equal(1) + }) + it('add the statuses to allStatuses if no timeline is given', () => { const state = cloneDeep(defaultState) const status = makeMockStatus({id: 1})