From 3e12bfbcef8894db5fc67167b6499584edae1ceb Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Wed, 29 May 2019 23:59:09 +0900 Subject: [PATCH] refs #630 Handle delete event for public streaming --- .../TimelineSpace/Contents/Public.spec.ts | 154 ++++++++++++++++++ .../TimelineSpace/Contents/Public.vue | 2 +- src/renderer/store/TimelineSpace.ts | 3 + .../store/TimelineSpace/Contents/Public.ts | 6 +- 4 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts new file mode 100644 index 00000000..93b76b1e --- /dev/null +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts @@ -0,0 +1,154 @@ +import { Account, Status, Application } from 'megalodon' +import Public, { PublicState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Public' + +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/Local', () => { + describe('mutations', () => { + let state: PublicState + + describe('deleteToot', () => { + describe('message is not reblogged', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '' + } + }) + it('should be deleted', () => { + Public.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', () => { + Public.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id) + expect(state.timeline).toEqual([status2]) + }) + }) + }) + }) +}) diff --git a/src/renderer/components/TimelineSpace/Contents/Public.vue b/src/renderer/components/TimelineSpace/Contents/Public.vue index 9b33eeed..f5096fa2 100644 --- a/src/renderer/components/TimelineSpace/Contents/Public.vue +++ b/src/renderer/components/TimelineSpace/Contents/Public.vue @@ -144,7 +144,7 @@ export default { this.$store.commit('TimelineSpace/Contents/Public/updateToot', message) }, deleteToot(message) { - this.$store.commit('TimelineSpace/Contents/Public/deleteToot', message) + this.$store.commit('TimelineSpace/Contents/Public/deleteToot', message.id) }, onScroll(event) { if (event.target.clientHeight + event.target.scrollTop >= document.getElementById('public').clientHeight - 10 && !this.lazyloading) { diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index 34c8367c..630f8476 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -386,6 +386,9 @@ const actions: ActionTree = { } commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', true, { root: true }) }) + ipcRenderer.on('delete-start-public-streaming', (_, id: string) => { + commit('TimelineSpace/Contents/Public/deleteToot', id, { root: true }) + }) }, startPublicStreaming: ({ state }) => { // @ts-ignore diff --git a/src/renderer/store/TimelineSpace/Contents/Public.ts b/src/renderer/store/TimelineSpace/Contents/Public.ts index 1af4de27..64370843 100644 --- a/src/renderer/store/TimelineSpace/Contents/Public.ts +++ b/src/renderer/store/TimelineSpace/Contents/Public.ts @@ -76,12 +76,12 @@ const mutations: MutationTree = { } }) }, - [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 } }) },