A bit more advanced status merging.

This commit is contained in:
Roger Braun 2016-11-18 16:05:04 +01:00
parent 4fcb60487c
commit 8723c35d43
2 changed files with 11 additions and 5 deletions

View file

@ -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) {

View file

@ -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', () => {