refs #1096 Reject duplicated status when append statuses in Lists
This commit is contained in:
parent
9cdeba0df5
commit
b48a877f5d
|
@ -85,6 +85,38 @@ const status2: Status = {
|
||||||
pinned: null
|
pinned: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rebloggedStatus: Status = {
|
||||||
|
id: '3',
|
||||||
|
uri: 'http://example.com',
|
||||||
|
url: 'http://example.com',
|
||||||
|
account: account,
|
||||||
|
in_reply_to_id: null,
|
||||||
|
in_reply_to_account_id: null,
|
||||||
|
reblog: status1,
|
||||||
|
content: '',
|
||||||
|
created_at: '2019-03-31T21:40:32',
|
||||||
|
emojis: [],
|
||||||
|
replies_count: 0,
|
||||||
|
reblogs_count: 0,
|
||||||
|
favourites_count: 0,
|
||||||
|
reblogged: null,
|
||||||
|
favourited: null,
|
||||||
|
muted: null,
|
||||||
|
sensitive: false,
|
||||||
|
spoiler_text: '',
|
||||||
|
visibility: 'public',
|
||||||
|
media_attachments: [],
|
||||||
|
mentions: [],
|
||||||
|
tags: [],
|
||||||
|
card: null,
|
||||||
|
poll: null,
|
||||||
|
application: {
|
||||||
|
name: 'Web'
|
||||||
|
} as Application,
|
||||||
|
language: null,
|
||||||
|
pinned: null
|
||||||
|
}
|
||||||
|
|
||||||
describe('TimelineSpace/Contents/Lists/Show', () => {
|
describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||||
describe('mutations', () => {
|
describe('mutations', () => {
|
||||||
let state: ShowState
|
let state: ShowState
|
||||||
|
@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||||
|
|
||||||
describe('message is reblogged', () => {
|
describe('message is reblogged', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const rebloggedStatus: Status = {
|
|
||||||
id: '3',
|
|
||||||
uri: 'http://example.com',
|
|
||||||
url: 'http://example.com',
|
|
||||||
account: account,
|
|
||||||
in_reply_to_id: null,
|
|
||||||
in_reply_to_account_id: null,
|
|
||||||
reblog: status1,
|
|
||||||
content: '',
|
|
||||||
created_at: '2019-03-31T21:40:32',
|
|
||||||
emojis: [],
|
|
||||||
replies_count: 0,
|
|
||||||
reblogs_count: 0,
|
|
||||||
favourites_count: 0,
|
|
||||||
reblogged: null,
|
|
||||||
favourited: null,
|
|
||||||
muted: null,
|
|
||||||
sensitive: false,
|
|
||||||
spoiler_text: '',
|
|
||||||
visibility: 'public',
|
|
||||||
media_attachments: [],
|
|
||||||
mentions: [],
|
|
||||||
tags: [],
|
|
||||||
card: null,
|
|
||||||
poll: null,
|
|
||||||
application: {
|
|
||||||
name: 'Web'
|
|
||||||
} as Application,
|
|
||||||
language: null,
|
|
||||||
pinned: null
|
|
||||||
}
|
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
|
@ -153,5 +154,79 @@ describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('appendTimeline', () => {
|
||||||
|
describe('heading', () => {
|
||||||
|
describe('normal', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
state = {
|
||||||
|
lazyLoading: false,
|
||||||
|
heading: true,
|
||||||
|
timeline: [status2, status1],
|
||||||
|
unreadTimeline: [],
|
||||||
|
filter: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('should be updated timeline', () => {
|
||||||
|
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
|
expect(state.unreadTimeline).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('duplicated status', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
state = {
|
||||||
|
lazyLoading: false,
|
||||||
|
heading: true,
|
||||||
|
timeline: [rebloggedStatus, status2, status1],
|
||||||
|
unreadTimeline: [],
|
||||||
|
filter: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('should not be updated timeline', () => {
|
||||||
|
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
|
expect(state.unreadTimeline).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('not heading', () => {
|
||||||
|
describe('normal', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
state = {
|
||||||
|
lazyLoading: false,
|
||||||
|
heading: false,
|
||||||
|
timeline: [status2, status1],
|
||||||
|
unreadTimeline: [],
|
||||||
|
filter: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('should be updated timeline', () => {
|
||||||
|
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
|
expect(state.timeline).toEqual([status2, status1])
|
||||||
|
expect(state.unreadTimeline).toEqual([rebloggedStatus])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('duplicated status', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
state = {
|
||||||
|
lazyLoading: false,
|
||||||
|
heading: false,
|
||||||
|
timeline: [rebloggedStatus, status2, status1],
|
||||||
|
unreadTimeline: [],
|
||||||
|
filter: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('should not be updated timeline', () => {
|
||||||
|
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
|
expect(state.unreadTimeline).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -39,10 +39,13 @@ const mutations: MutationTree<ShowState> = {
|
||||||
state.heading = value
|
state.heading = value
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => {
|
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => {
|
||||||
if (state.heading) {
|
// Reject duplicated status in timeline
|
||||||
state.timeline = [update].concat(state.timeline)
|
if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
|
||||||
} else {
|
if (state.heading) {
|
||||||
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
state.timeline = [update].concat(state.timeline)
|
||||||
|
} else {
|
||||||
|
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array<Status>) => {
|
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array<Status>) => {
|
||||||
|
|
Loading…
Reference in New Issue