refs #630 Handle delete event for list streaming
This commit is contained in:
parent
3e12bfbcef
commit
449fb00a74
|
@ -0,0 +1,154 @@
|
|||
import { Account, Status, Application } from 'megalodon'
|
||||
import Show, { ShowState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
|
||||
|
||||
const account: Account = {
|
||||
id: '1',
|
||||
username: 'h3poteto',
|
||||
acct: 'h3poteto@pleroma.io',
|
||||
display_name: 'h3poteto',
|
||||
locked: false,
|
||||
created_at: '2019-03-26T21:30:32',
|
||||
followers_count: 10,
|
||||
following_count: 10,
|
||||
statuses_count: 100,
|
||||
note: 'engineer',
|
||||
url: 'https://pleroma.io',
|
||||
avatar: '',
|
||||
avatar_static: '',
|
||||
header: '',
|
||||
header_static: '',
|
||||
emojis: [],
|
||||
moved: null,
|
||||
fields: null,
|
||||
bot: false
|
||||
}
|
||||
const status1: Status = {
|
||||
id: '1',
|
||||
uri: 'http://example.com',
|
||||
url: 'http://example.com',
|
||||
account: account,
|
||||
in_reply_to_id: null,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: 'hoge',
|
||||
created_at: '2019-03-26T21: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,
|
||||
application: {
|
||||
name: 'Web'
|
||||
} as Application,
|
||||
language: null,
|
||||
pinned: null
|
||||
}
|
||||
const status2: Status = {
|
||||
id: '2',
|
||||
uri: 'http://example.com',
|
||||
url: 'http://example.com',
|
||||
account: account,
|
||||
in_reply_to_id: null,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: 'fuga',
|
||||
created_at: '2019-03-26T21: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,
|
||||
application: {
|
||||
name: 'Web'
|
||||
} as Application,
|
||||
language: null,
|
||||
pinned: null
|
||||
}
|
||||
|
||||
describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||
describe('mutations', () => {
|
||||
let state: ShowState
|
||||
|
||||
describe('deleteToot', () => {
|
||||
describe('message is not reblogged', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
Show.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
|
||||
expect(state.timeline).toEqual([status2])
|
||||
})
|
||||
})
|
||||
|
||||
describe('message is reblogged', () => {
|
||||
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,
|
||||
application: {
|
||||
name: 'Web'
|
||||
} as Application,
|
||||
language: null,
|
||||
pinned: null
|
||||
}
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, rebloggedStatus],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
Show.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
|
||||
expect(state.timeline).toEqual([status2])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
|
@ -143,7 +143,7 @@ export default {
|
|||
this.$store.commit('TimelineSpace/Contents/Lists/Show/updateToot', message)
|
||||
},
|
||||
deleteToot(message) {
|
||||
this.$store.commit('TimelineSpace/Contents/Lists/Show/deleteToot', message)
|
||||
this.$store.commit('TimelineSpace/Contents/Lists/Show/deleteToot', message.id)
|
||||
},
|
||||
onScroll(event) {
|
||||
if (
|
||||
|
|
|
@ -78,12 +78,12 @@ const mutations: MutationTree<ShowState> = {
|
|||
}
|
||||
})
|
||||
},
|
||||
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
|
||||
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
|
||||
state.timeline = state.timeline.filter(toot => {
|
||||
if (toot.reblog !== null && toot.reblog.id === message.id) {
|
||||
if (toot.reblog !== null && toot.reblog.id === id) {
|
||||
return false
|
||||
} else {
|
||||
return toot.id !== message.id
|
||||
return toot.id !== id
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -109,6 +109,9 @@ const actions: ActionTree<ShowState, RootState> = {
|
|||
commit(MUTATION_TYPES.ARCHIVE_TIMELINE)
|
||||
}
|
||||
})
|
||||
ipcRenderer.on('delete-start-list-streaming', (_, id: string) => {
|
||||
commit(MUTATION_TYPES.DELETE_TOOT, id)
|
||||
})
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
|
@ -126,6 +129,7 @@ const actions: ActionTree<ShowState, RootState> = {
|
|||
return new Promise(resolve => {
|
||||
ipcRenderer.removeAllListeners('error-start-list-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-list-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-list-streaming')
|
||||
ipcRenderer.send('stop-list-streaming')
|
||||
resolve()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue