From 8723c35d4305a4ff5d01dee8707c1cc25b405cd2 Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Fri, 18 Nov 2016 16:05:04 +0100
Subject: [PATCH] A bit more advanced status merging.

---
 src/modules/statuses.js                  | 10 ++++++++--
 test/unit/specs/modules/statuses.spec.js |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 7fa8a7b2..268e64fb 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -153,6 +153,11 @@ export const findMaxId = (...args) => {
 
 export const mutations = {
   addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
+
+    // Merge in the new status into the old ones.
+    mergeStatuses(state.allStatuses, statuses)
+
+    // Get relevant timeline
     const timelineObject = state.timelines[timeline]
 
     // Set new maxId
@@ -163,7 +168,6 @@ export const mutations = {
     // const statusesByType = groupStatusesByType(statuses)
 
     state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
-    mergeStatuses(state.allStatuses, state.timelines[timeline].statuses)
 
     // Set up retweets with most current status
     const getRetweets = (result, status) => {
@@ -175,7 +179,9 @@ export const mutations = {
 
     const retweets = reduce(statuses, getRetweets, [])
 
-    state.allStatuses = unionBy(retweets, state.allStatuses, 'id')
+    // state.allStatuses = unionBy(retweets, state.allStatuses, 'id')
+
+    mergeStatuses(state.allStatuses, retweets)
 
     each(state.allStatuses, (status) => {
       if (status.retweeted_status) {
diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js
index 02013039..0370d4ae 100644
--- a/test/unit/specs/modules/statuses.spec.js
+++ b/test/unit/specs/modules/statuses.spec.js
@@ -86,11 +86,11 @@ describe('The Statuses module', () => {
     // It adds both statuses, but only the retweet to visible.
     mutations.addNewStatuses(state, { statuses: [retweet], timeline: 'public', showImmediately: true })
     expect(state.timelines.public.visibleStatuses).to.have.length(1)
-    expect(state.allStatuses).to.eql([status, retweet])
+    expect(state.allStatuses).to.eql([retweet, status])
 
     // It refers to the modified status.
     mutations.addNewStatuses(state, { statuses: [modStatus], timeline: 'public' })
-    expect(state.allStatuses).to.eql([modStatus, retweet])
+    expect(state.allStatuses).to.eql([retweet, modStatus])
     expect(retweet.retweeted_status).to.eql(modStatus)
   })
 
@@ -127,7 +127,7 @@ describe('The Statuses module', () => {
     mutations.addNewStatuses(state, { statuses: [retweet], showImmediately: false, timeline: 'public' })
     expect(state.timelines.public.visibleStatuses).to.have.length(1)
     expect(state.allStatuses).to.have.length(2)
-    expect(state.allStatuses[0]).to.equal(modStatus)
+    expect(state.allStatuses[0]).to.eql(modStatus)
   })
 
   it('handles favorite actions', () => {