Add noIdUpdate option for addNewStatuses action.

This fixes #11.
This commit is contained in:
Roger Braun 2016-11-28 21:25:36 +01:00
parent bb1b3c3975
commit 9681bb7bfd
3 changed files with 25 additions and 7 deletions

View file

@ -86,7 +86,7 @@ const mergeOrAdd = (arr, item) => {
} }
} }
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {} }) => { const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false }) => {
// Sanity check // Sanity check
if (!isArray(statuses)) { if (!isArray(statuses)) {
return false return false
@ -97,7 +97,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
// Set the maxId to the new id if it's larger. // Set the maxId to the new id if it's larger.
const updateMaxId = ({id}) => { const updateMaxId = ({id}) => {
if (!timeline) { return false } if (!timeline || noIdUpdate) { return false }
timelineObject.maxId = max([id, timelineObject.maxId]) timelineObject.maxId = max([id, timelineObject.maxId])
} }
@ -242,8 +242,8 @@ export const mutations = {
const statuses = { const statuses = {
state: defaultState, state: defaultState,
actions: { actions: {
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false }) { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) {
commit('addNewStatuses', { statuses, showImmediately, timeline, user: rootState.users.currentUser }) commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser })
}, },
favorite ({ rootState, commit }, status) { favorite ({ rootState, commit }, status) {
// Optimistic favoriting... // Optimistic favoriting...

View file

@ -7,8 +7,12 @@ const postStatus = ({ store, status, media = [], inReplyToStatusId = undefined }
return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, mediaIds, inReplyToStatusId}) return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, mediaIds, inReplyToStatusId})
.then((data) => data.json()) .then((data) => data.json())
.then((data) => { .then((data) => {
store.dispatch('addNewStatuses', store.dispatch('addNewStatuses', {
{ statuses: [data], timeline: 'friends', showImmediately: true }) statuses: [data],
timeline: 'friends',
showImmediately: true,
noIdUpdate: true // To prevent missing notices on next pull.
})
}) })
} }

View file

@ -104,7 +104,7 @@ describe('The Statuses module', () => {
status.uri = 'xxx' status.uri = 'xxx'
const deletion = makeMockStatus({id: 2, is_post_verb: false}) const deletion = makeMockStatus({id: 2, is_post_verb: false})
deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.'
deletion.uri= 'xxx' deletion.uri = 'xxx'
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' })
mutations.addNewStatuses(state, { statuses: [deletion], showImmediately: true, timeline: 'public' }) mutations.addNewStatuses(state, { statuses: [deletion], showImmediately: true, timeline: 'public' })
@ -115,6 +115,20 @@ describe('The Statuses module', () => {
expect(state.timelines.public.maxId).to.eql(2) expect(state.timelines.public.maxId).to.eql(2)
}) })
it('does not update the maxId when the noIdUpdate flag is set', () => {
const state = cloneDeep(defaultState)
const status = makeMockStatus({id: 1})
const secondStatus = makeMockStatus({id: 2})
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' })
expect(state.timelines.public.maxId).to.eql(1)
mutations.addNewStatuses(state, { statuses: [secondStatus], showImmediately: true, timeline: 'public', noIdUpdate: true })
expect(state.timelines.public.statuses).to.eql([secondStatus, status])
expect(state.timelines.public.visibleStatuses).to.eql([secondStatus, status])
expect(state.timelines.public.maxId).to.eql(1)
})
it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => { it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => {
const state = cloneDeep(defaultState) const state = cloneDeep(defaultState)
const status = makeMockStatus({id: 2}) const status = makeMockStatus({id: 2})