refs #1096 Reject duplicated status when append statuses in Mentions

This commit is contained in:
AkiraFukushima 2019-11-13 23:35:00 +09:00
parent a68b34c252
commit 542eaf2959
2 changed files with 70 additions and 28 deletions

View File

@ -172,35 +172,74 @@ describe('TimelineSpace/Contents/Mentions', () => {
describe('appendMentions', () => {
describe('heading', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [notification1],
unreadMentions: [],
filter: ''
}
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [notification1],
unreadMentions: [],
filter: ''
}
})
it('should update mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification2, notification1])
expect(state.unreadMentions).toEqual([])
})
})
it('should update mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification2, notification1])
expect(state.unreadMentions).toEqual([])
describe('duplicated status', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [notification2, notification1],
unreadMentions: [],
filter: ''
}
})
it('should not be updated mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification2, notification1])
expect(state.unreadMentions).toEqual([])
})
})
})
describe('not heading', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [notification1],
unreadMentions: [],
filter: ''
}
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [notification1],
unreadMentions: [],
filter: ''
}
})
it('should update mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification1])
expect(state.unreadMentions).toEqual([notification2])
})
})
it('should update mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification1])
expect(state.unreadMentions).toEqual([notification2])
describe('duplicated status', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [notification1],
unreadMentions: [notification2],
filter: ''
}
})
it('should not be updated mentions', () => {
Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2)
expect(state.mentions).toEqual([notification1])
expect(state.unreadMentions).toEqual([notification2])
})
})
})
})

View File

@ -40,10 +40,13 @@ const mutations: MutationTree<MentionsState> = {
state.heading = value
},
[MUTATION_TYPES.APPEND_MENTIONS]: (state, update: Notification) => {
if (state.heading) {
state.mentions = [update].concat(state.mentions)
} else {
state.unreadMentions = [update].concat(state.unreadMentions)
// Reject duplicated status in timeline
if (!state.mentions.find(item => item.id === update.id) && !state.unreadMentions.find(item => item.id === update.id)) {
if (state.heading) {
state.mentions = [update].concat(state.mentions)
} else {
state.unreadMentions = [update].concat(state.unreadMentions)
}
}
},
[MUTATION_TYPES.UPDATE_MENTIONS]: (state, messages: Array<Notification>) => {