Merge pull request #930 from h3poteto/iss-630

closes #630 Handle delete event of streamings
This commit is contained in:
AkiraFukushima 2019-05-30 22:07:57 +09:00 committed by GitHub
commit a3648e9548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 1313 additions and 215 deletions

View File

@ -0,0 +1,154 @@
import { Account, Status, Application } from 'megalodon'
import DirectMessages, { DirectMessagesState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/DirectMessages'
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/DirectMessages', () => {
describe('mutations', () => {
let state: DirectMessagesState
describe('deleteToot', () => {
describe('message is not reblogged', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: [],
filter: ''
}
})
it('should be deleted', () => {
DirectMessages.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', () => {
DirectMessages.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
})
})
})

View File

@ -0,0 +1,154 @@
import { Account, Status, Application } from 'megalodon'
import Tag, { TagState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Hashtag/Tag'
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/Hashtag/Tag', () => {
describe('mutations', () => {
let state: TagState
describe('deleteToot', () => {
describe('message is not reblogged', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: [],
filter: ''
}
})
it('should be deleted', () => {
Tag.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', () => {
Tag.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
})
})
})

View File

@ -277,7 +277,7 @@ describe('TimelineSpace/Contents/Home', () => {
}
})
it('should be deleted', () => {
Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1)
Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
@ -325,7 +325,7 @@ describe('TimelineSpace/Contents/Home', () => {
}
})
it('should be deleted', () => {
Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1)
Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})

View File

@ -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])
})
})
})
})
})

View File

@ -0,0 +1,154 @@
import { Account, Status, Application } from 'megalodon'
import Local, { LocalState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Local'
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: LocalState
describe('deleteToot', () => {
describe('message is not reblogged', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: [],
filter: ''
}
})
it('should be deleted', () => {
Local.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', () => {
Local.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
})
})
})

View File

@ -45,7 +45,7 @@ const account2: Account = {
bot: false
}
const status: Status = {
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
@ -76,19 +76,81 @@ const status: Status = {
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
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 rebloggedStatus: Status = {
id: '3',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: status2,
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 notification1: Notification = {
id: '1',
account: account2,
status: status,
type: 'favourite',
status: status1,
type: 'mention',
created_at: '2019-04-01T17:01:32'
}
const notification2: Notification = {
id: '2',
account: account2,
status: status,
type: 'reblog',
status: rebloggedStatus,
type: 'mention',
created_at: '2019-04-01T17:01:32'
}
@ -184,13 +246,46 @@ describe('TimelineSpace/Contents/Mentions', () => {
}
})
it('should be updated', () => {
const favourited: Status = Object.assign(status, {
const favourited: Status = Object.assign(status1, {
favourited: true
})
Mentions.mutations![MUTATION_TYPES.UPDATE_TOOT](state, favourited)
expect(state.mentions[0].status!.favourited).toEqual(true)
expect(state.mentions[0].status!.favourited).toEqual(null)
expect(state.mentions[1].status!.favourited).toEqual(true)
})
})
describe('deleteToot', () => {
describe('message is not reblogged', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [notification2, notification1],
unreadMentions: [],
filter: ''
}
})
it('should be deleted', () => {
Mentions.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification1.status!.id)
expect(state.mentions.length).toEqual(1)
})
})
describe('message is reblogged', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [notification2, notification1],
unreadMentions: [],
filter: ''
}
})
it('should be deleted', () => {
Mentions.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification2.status!.id)
expect(state.mentions.length).toEqual(1)
})
})
})
})
})

View File

@ -0,0 +1,185 @@
import { Account, Notification, Status, Application } from 'megalodon'
import Notifications, { NotificationsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Notifications'
const account1: 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 account2: Account = {
id: '2',
username: 'h3poteto',
acct: 'h3poteto@mstdn.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://mstdn.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: account1,
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: account1,
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 rebloggedStatus: Status = {
id: '3',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: status2,
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 notification1: Notification = {
id: '1',
account: account2,
status: status1,
type: 'favourite',
created_at: '2019-04-01T17:01:32'
}
const notification2: Notification = {
id: '2',
account: account2,
status: rebloggedStatus,
type: 'mention',
created_at: '2019-04-01T17:01:32'
}
describe('TimelineSpace/Contents/Notifications', () => {
describe('mutations', () => {
let state: NotificationsState
describe('deleteToot', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
notifications: [notification2, notification1],
unreadNotifications: [],
filter: ''
}
})
describe('message is not reblogged', () => {
it('should be deleted', () => {
Notifications.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification1.status!.id)
expect(state.notifications.length).toEqual(1)
})
})
describe('message is reblogged', () => {
it('should be deleted', () => {
Notifications.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification2.status!.id)
expect(state.notifications.length).toEqual(1)
})
})
})
})
})

View File

@ -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])
})
})
})
})
})

View File

@ -457,6 +457,9 @@ ipcMain.on('start-user-streaming', (event: Event, obj: StreamingSetting) => {
app.dock.setBadge('•')
}
},
(id: string) => {
event.sender.send('delete-start-user-streaming', id)
},
(err: Error) => {
log.error(err)
// In macOS, sometimes window is closed (not quit).
@ -501,6 +504,9 @@ ipcMain.on('start-directmessages-streaming', (event: Event, obj: StreamingSettin
(update: Status) => {
event.sender.send('update-start-directmessages-streaming', update)
},
(id: string) => {
event.sender.send('delete-start-directmessages-streaming', id)
},
(err: Error) => {
log.error(err)
if (!event.sender.isDestroyed()) {
@ -542,6 +548,9 @@ ipcMain.on('start-local-streaming', (event: Event, obj: StreamingSetting) => {
(update: Status) => {
event.sender.send('update-start-local-streaming', update)
},
(id: string) => {
event.sender.send('delete-start-local-streaming', id)
},
(err: Error) => {
log.error(err)
if (!event.sender.isDestroyed()) {
@ -583,6 +592,9 @@ ipcMain.on('start-public-streaming', (event: Event, obj: StreamingSetting) => {
(update: Status) => {
event.sender.send('update-start-public-streaming', update)
},
(id: string) => {
event.sender.send('delete-start-public-streaming', id)
},
(err: Error) => {
log.error(err)
if (!event.sender.isDestroyed()) {
@ -628,6 +640,9 @@ ipcMain.on('start-list-streaming', (event: Event, obj: ListID & StreamingSetting
(update: Status) => {
event.sender.send('update-start-list-streaming', update)
},
(id: string) => {
event.sender.send('delete-start-list-streaming', id)
},
(err: Error) => {
log.error(err)
if (!event.sender.isDestroyed()) {
@ -673,6 +688,9 @@ ipcMain.on('start-tag-streaming', (event: Event, obj: Tag & StreamingSetting) =>
(update: Status) => {
event.sender.send('update-start-tag-streaming', update)
},
(id: string) => {
event.sender.send('delete-start-tag-streaming', id)
},
(err: Error) => {
log.error(err)
if (!event.sender.isDestroyed()) {

View File

@ -6,15 +6,12 @@ export default class Streaming {
private client: Mastodon
private listener: StreamListener | null
constructor (account: LocalAccount) {
this.client = new Mastodon(
account.accessToken!,
account.baseURL + '/api/v1'
)
constructor(account: LocalAccount) {
this.client = new Mastodon(account.accessToken!, account.baseURL + '/api/v1')
this.listener = null
}
startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
this.listener = this.client.stream('/streaming/user')
this.listener.on('connect', _ => {
@ -29,6 +26,10 @@ export default class Streaming {
notificationCallback(notification)
})
this.listener.on('delete', (id: string) => {
deleteCallback(id)
})
this.listener.on('error', (err: Error) => {
errCallback(err)
})
@ -38,7 +39,7 @@ export default class Streaming {
})
}
start (path: string, updateCallback: Function, errCallback: Function) {
start(path: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
this.listener = this.client.stream(path)
this.listener.on('connect', _ => {
log.info(`${path} started`)
@ -48,6 +49,10 @@ export default class Streaming {
updateCallback(status)
})
this.listener.on('delete', (id: string) => {
deleteCallback(id)
})
this.listener.on('error', (err: Error) => {
errCallback(err)
})
@ -57,7 +62,7 @@ export default class Streaming {
})
}
stop () {
stop() {
if (this.listener) {
this.listener.removeAllListeners('connect')
this.listener.removeAllListeners('update')

View File

@ -7,29 +7,29 @@ export default class StreamingManager {
private websocket: WebSocket
private useWebsocket: boolean
constructor (account: LocalAccount, useWebsocket = false) {
constructor(account: LocalAccount, useWebsocket = false) {
this.streaming = new Streaming(account)
this.websocket = new WebSocket(account)
this.useWebsocket = useWebsocket
}
startUser (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
startUser(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
if (this.useWebsocket) {
this._startUserSocket(updateCallback, notificationCallback, errCallback)
this._startUserSocket(updateCallback, notificationCallback, deleteCallback, errCallback)
} else {
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
this._startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
}
}
start (path: string, params: string, updateCallback: Function, errCallback: Function) {
start(path: string, params: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
if (this.useWebsocket) {
this._startSocket(path, params, updateCallback, errCallback)
this._startSocket(path, params, updateCallback, deleteCallback, errCallback)
} else {
this._startStreaming(path, params, updateCallback, errCallback)
this._startStreaming(path, params, updateCallback, deleteCallback, errCallback)
}
}
stop () {
stop() {
this._stopStreaming()
this._stopSocket()
}
@ -37,43 +37,35 @@ export default class StreamingManager {
/**
* Using streaming for Mastodon
*/
_startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
this.streaming.startUserStreaming(updateCallback, notificationCallback, errCallback)
_startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
this.streaming.startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
}
_startStreaming (path: string, params: string, updateCallback: Function, errCallback: Function) {
_startStreaming(path: string, params: string, updateCallback: Function, deleteCallback, errCallback: Function) {
const target = `/streaming/${path}?${params}`
this.streaming.start(
target,
updateCallback,
errCallback
)
this.streaming.start(target, updateCallback, deleteCallback, errCallback)
}
_stopStreaming () {
_stopStreaming() {
this.streaming.stop()
}
/**
* Using websocket for Pleroma
*/
_startUserSocket (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
this.websocket.startUserStreaming(updateCallback, notificationCallback, errCallback)
_startUserSocket(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
this.websocket.startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
}
_startSocket (path: string, params: string, updateCallback: Function, errCallback: Function) {
_startSocket(path: string, params: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
let stream = path
if (stream === 'public/local') {
stream = 'public:local'
}
this.websocket.start(
`${stream}&${params}`,
updateCallback,
errCallback
)
this.websocket.start(`${stream}&${params}`, updateCallback, deleteCallback, errCallback)
}
_stopSocket () {
_stopSocket() {
this.websocket.stop()
}
}

View File

@ -6,16 +6,13 @@ export default class WebSocket {
private client: Mastodon
private listener: SocketListener | null
constructor (account: LocalAccount) {
constructor(account: LocalAccount) {
const url = account.baseURL.replace(/^https:\/\//, 'wss://')
this.client = new Mastodon(
account.accessToken!,
url + '/api/v1'
)
this.client = new Mastodon(account.accessToken!, url + '/api/v1')
this.listener = null
}
startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
this.listener = this.client.socket('/streaming', 'user')
this.listener.on('connect', _ => {
@ -30,6 +27,10 @@ export default class WebSocket {
notificationCallback(notification)
})
this.listener.on('delete', (id: string) => {
deleteCallback(id)
})
this.listener.on('error', (err: Error) => {
errCallback(err)
})
@ -49,7 +50,7 @@ export default class WebSocket {
* When hashtag timeline, the path is `hashtag&tag=tag_name`.
* When list timeline, the path is `list&list=list_id`.
*/
start (stream: string, updateCallback: Function, errCallback: Function) {
start(stream: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
this.listener = this.client.socket('/streaming', stream)
this.listener.on('connect', _ => {
log.info(`/streaming/?stream=${stream} started`)
@ -59,6 +60,10 @@ export default class WebSocket {
updateCallback(status)
})
this.listener.on('delete', (id: string) => {
deleteCallback(id)
})
this.listener.on('error', (err: Error) => {
errCallback(err)
})
@ -68,7 +73,7 @@ export default class WebSocket {
})
}
stop () {
stop() {
if (this.listener) {
this.listener.removeAllListeners('connect')
this.listener.removeAllListeners('update')

View File

@ -167,7 +167,7 @@ export default {
this.$store.commit('TimelineSpace/Contents/DirectMessages/updateToot', message)
},
deleteToot(message) {
this.$store.commit('TimelineSpace/Contents/DirectMessages/deleteToot', message)
this.$store.commit('TimelineSpace/Contents/DirectMessages/deleteToot', message.id)
},
async reload() {
this.$store.commit('TimelineSpace/changeLoading', true)

View File

@ -142,7 +142,7 @@ export default {
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/updateToot', toot)
},
deleteToot(toot) {
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/deleteToot', toot)
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/deleteToot', toot.id)
},
onScroll(event) {
if (

View File

@ -1,32 +1,29 @@
<template>
<div id="home" v-shortkey="shortcutEnabled ? {next: ['j']} : {}" @shortkey="handleKey">
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
<div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()">
</div>
<transition-group name="timeline" tag="div">
<div class="home-timeline" v-for="message in filteredTimeline" :key="message.uri + message.id">
<toot
:message="message"
:filter="filter"
:focused="message.uri + message.id === focusedId"
:overlaid="modalOpened"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@focusRight="focusSidebar"
@selectToot="focusToot(message)"
<div id="home" v-shortkey="shortcutEnabled ? { next: ['j'] } : {}" @shortkey="handleKey">
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
<div v-shortkey="{ linux: ['ctrl', 'r'], mac: ['meta', 'r'] }" @shortkey="reload()"></div>
<transition-group name="timeline" tag="div">
<div class="home-timeline" v-for="message in filteredTimeline" :key="message.uri + message.id">
<toot
:message="message"
:filter="filter"
:focused="message.uri + message.id === focusedId"
:overlaid="modalOpened"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@focusRight="focusSidebar"
@selectToot="focusToot(message)"
>
</toot>
</toot>
</div>
</transition-group>
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor"></div>
<div :class="openSideBar ? 'upper-with-side-bar' : 'upper'" v-show="!heading">
<el-button type="primary" icon="el-icon-arrow-up" @click="upper" circle> </el-button>
</div>
</transition-group>
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor">
</div>
<div :class="openSideBar ? 'upper-with-side-bar' : 'upper'" v-show="!heading">
<el-button type="primary" icon="el-icon-arrow-up" @click="upper" circle>
</el-button>
</div>
</div>
</template>
<script>
@ -40,7 +37,7 @@ export default {
name: 'home',
components: { Toot },
mixins: [reloadable],
data () {
data() {
return {
focusedId: null
}
@ -58,10 +55,8 @@ export default {
showReblogs: state => state.TimelineSpace.Contents.Home.showReblogs,
showReplies: state => state.TimelineSpace.Contents.Home.showReplies
}),
...mapGetters('TimelineSpace/Modals', [
'modalOpened'
]),
shortcutEnabled: function () {
...mapGetters('TimelineSpace/Modals', ['modalOpened']),
shortcutEnabled: function() {
if (this.modalOpened) {
return false
}
@ -72,8 +67,8 @@ export default {
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
return currentIndex === -1
},
filteredTimeline () {
return this.timeline.filter((toot) => {
filteredTimeline() {
return this.timeline.filter(toot => {
if (toot.in_reply_to_id) {
return this.showReplies
} else if (toot.reblog) {
@ -84,27 +79,27 @@ export default {
})
}
},
mounted () {
mounted() {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
Event.$on('focus-timeline', () => {
// If focusedId does not change, we have to refresh focusedId because Toot component watch change events.
const previousFocusedId = this.focusedId
this.focusedId = 0
this.$nextTick(function () {
this.$nextTick(function() {
this.focusedId = previousFocusedId
})
})
},
beforeUpdate () {
beforeUpdate() {
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline && this.heading) {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
}
},
beforeDestroy () {
beforeDestroy() {
Event.$off('focus-timeline')
},
destroyed () {
destroyed() {
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/Home/archiveTimeline')
@ -114,15 +109,14 @@ export default {
}
},
watch: {
startReload: function (newState, oldState) {
startReload: function(newState, oldState) {
if (!oldState && newState) {
this.reload()
.finally(() => {
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
})
this.reload().finally(() => {
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
})
}
},
focusedId: function (newState, _oldState) {
focusedId: function(newState, _oldState) {
if (newState && this.heading) {
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', false)
} else if (newState === null && !this.heading) {
@ -132,32 +126,31 @@ export default {
}
},
methods: {
onScroll (event) {
onScroll(event) {
// for lazyLoading
if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementById('home').clientHeight - 10) && !this.lazyloading) {
this.$store.dispatch('TimelineSpace/Contents/Home/lazyFetchTimeline', this.timeline[this.timeline.length - 1])
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
if (event.target.clientHeight + event.target.scrollTop >= document.getElementById('home').clientHeight - 10 && !this.lazyloading) {
this.$store.dispatch('TimelineSpace/Contents/Home/lazyFetchTimeline', this.timeline[this.timeline.length - 1]).catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
}
// for unread control
if ((event.target.scrollTop > 10) && this.heading) {
if (event.target.scrollTop > 10 && this.heading) {
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', false)
} else if ((event.target.scrollTop <= 10) && !this.heading) {
} else if (event.target.scrollTop <= 10 && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
}
},
updateToot (message) {
updateToot(message) {
this.$store.commit('TimelineSpace/Contents/Home/updateToot', message)
},
deleteToot (message) {
this.$store.commit('TimelineSpace/Contents/Home/deleteToot', message)
deleteToot(message) {
this.$store.commit('TimelineSpace/Contents/Home/deleteToot', message.id)
},
async reload () {
async reload() {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
await this.reloadable()
@ -165,14 +158,11 @@ export default {
this.$store.commit('TimelineSpace/changeLoading', false)
}
},
upper () {
scrollTop(
document.getElementById('scrollable'),
0
)
upper() {
scrollTop(document.getElementById('scrollable'), 0)
this.focusedId = null
},
focusNext () {
focusNext() {
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
if (currentIndex === -1) {
this.focusedId = this.timeline[0].uri + this.timeline[0].id
@ -180,7 +170,7 @@ export default {
this.focusedId = this.timeline[currentIndex + 1].uri + this.timeline[currentIndex + 1].id
}
},
focusPrev () {
focusPrev() {
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
if (currentIndex === 0) {
this.focusedId = null
@ -188,13 +178,13 @@ export default {
this.focusedId = this.timeline[currentIndex - 1].uri + this.timeline[currentIndex - 1].id
}
},
focusToot (message) {
focusToot(message) {
this.focusedId = message.uri + message.id
},
focusSidebar () {
focusSidebar() {
Event.$emit('focus-sidebar')
},
handleKey (event) {
handleKey(event) {
switch (event.srcKey) {
case 'next':
this.focusedId = this.timeline[0].uri + this.timeline[0].id

View File

@ -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 (

View File

@ -144,7 +144,7 @@ export default {
this.$store.commit('TimelineSpace/Contents/Local/updateToot', message)
},
deleteToot(message) {
this.$store.commit('TimelineSpace/Contents/Local/deleteToot', message)
this.$store.commit('TimelineSpace/Contents/Local/deleteToot', message.id)
},
onScroll(event) {
if (event.target.clientHeight + event.target.scrollTop >= document.getElementById('local').clientHeight - 10 && !this.lazyloading) {

View File

@ -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) {

View File

@ -334,6 +334,11 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
}
commit('TimelineSpace/SideMenu/changeUnreadMentions', true, { root: true })
})
ipcRenderer.on('delete-start-user-streaming', (_, id: string) => {
commit('TimelineSpace/Contents/Home/deleteToot', id, { root: true })
commit('TimelineSpace/Contents/Notifications/deleteToot', id, { root: true })
commit('TimelineSpace/Contents/Mentions/deleteToot', id, { root: true })
})
},
startUserStreaming: ({ state }): Promise<{}> => {
// @ts-ignore
@ -356,6 +361,9 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
}
commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', true, { root: true })
})
ipcRenderer.on('delete-start-local-streaming', (_, id: string) => {
commit('TimelineSpace/Contents/Local/deleteToot', id, { root: true })
})
},
startLocalStreaming: ({ state }) => {
// @ts-ignore
@ -378,6 +386,9 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
}
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
@ -400,6 +411,9 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
}
commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', true, { root: true })
})
ipcRenderer.on('delete-start-directmessages-streaming', (_, id: string) => {
commit('TimelineSpace/Contents/DirectMessages/deleteToot', id, { root: true })
})
},
startDirectMessagesStreaming: ({ state }) => {
// @ts-ignore
@ -418,6 +432,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
ipcRenderer.removeAllListeners('update-start-user-streaming')
ipcRenderer.removeAllListeners('mention-start-user-streaming')
ipcRenderer.removeAllListeners('notification-start-user-streaming')
ipcRenderer.removeAllListeners('delete-start-user-streaming')
ipcRenderer.removeAllListeners('error-start-user-streaming')
},
stopUserStreaming: () => {
@ -426,6 +441,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
unbindLocalStreaming: () => {
ipcRenderer.removeAllListeners('error-start-local-streaming')
ipcRenderer.removeAllListeners('update-start-local-streaming')
ipcRenderer.removeAllListeners('delete-start-local-streaming')
},
stopLocalStreaming: () => {
ipcRenderer.send('stop-local-streaming')
@ -433,6 +449,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
unbindPublicStreaming: () => {
ipcRenderer.removeAllListeners('error-start-public-streaming')
ipcRenderer.removeAllListeners('update-start-public-streaming')
ipcRenderer.removeAllListeners('delete-start-public-streaming')
},
stopPublicStreaming: () => {
ipcRenderer.send('stop-public-streaming')
@ -440,6 +457,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
unbindDirectMessagesStreaming: () => {
ipcRenderer.removeAllListeners('error-start-directmessages-streaming')
ipcRenderer.removeAllListeners('update-start-directmessages-streaming')
ipcRenderer.removeAllListeners('delete-start-directmessages-streaming')
},
stopDirectMessagesStreaming: () => {
ipcRenderer.send('stop-directmessages-streaming')

View File

@ -3,10 +3,10 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface DirectMessagesState {
lazyLoading: boolean,
heading: boolean,
timeline: Array<Status>,
unreadTimeline: Array<Status>,
lazyLoading: boolean
heading: boolean
timeline: Array<Status>
unreadTimeline: Array<Status>
filter: string
}
@ -49,23 +49,23 @@ const mutations: MutationTree<DirectMessagesState> = {
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = messages
},
[MUTATION_TYPES.MERGE_TIMELINE]: (state) => {
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
state.unreadTimeline = []
},
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = state.timeline.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_TIMELINE]: (state) => {
[MUTATION_TYPES.ARCHIVE_TIMELINE]: state => {
state.timeline = state.timeline.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_TIMELINE]: (state) => {
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
// Replace target message in DirectMessagesTimeline and notifications
state.timeline = state.timeline.map((toot) => {
state.timeline = state.timeline.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -80,12 +80,12 @@ const mutations: MutationTree<DirectMessagesState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === id) {
return false
} else {
return toot.id !== message.id
return toot.id !== id
}
})
},
@ -96,10 +96,7 @@ const mutations: MutationTree<DirectMessagesState> = {
const actions: ActionTree<DirectMessagesState, RootState> = {
fetchTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/direct', { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
@ -110,11 +107,9 @@ const actions: ActionTree<DirectMessagesState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get<Array<Status>>('/timelines/direct', { max_id: lastStatus.id, limit: 40 })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Status>>('/timelines/direct', { max_id: lastStatus.id, limit: 40 })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -5,10 +5,10 @@ import { RootState } from '@/store'
import { LoadPositionWithTag } from '@/types/loadPosition'
export interface TagState {
timeline: Array<Status>,
unreadTimeline: Array<Status>,
lazyLoading: boolean,
heading: boolean,
timeline: Array<Status>
unreadTimeline: Array<Status>
lazyLoading: boolean
heading: boolean
filter: string
}
@ -48,22 +48,22 @@ const mutations: MutationTree<TagState> = {
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array<Status>) => {
state.timeline = timeline
},
[MUTATION_TYPES.MERGE_TIMELINE]: (state) => {
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
state.unreadTimeline = []
},
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = state.timeline.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_TIMELINE]: (state) => {
[MUTATION_TYPES.ARCHIVE_TIMELINE]: state => {
state.timeline = state.timeline.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_TIMELINE]: (state) => {
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.map((toot) => {
state.timeline = state.timeline.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -78,12 +78,12 @@ const mutations: MutationTree<TagState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === id) {
return false
} else {
return toot.id !== message.id
return toot.id !== id
}
})
},
@ -97,10 +97,7 @@ const mutations: MutationTree<TagState> = {
const actions: ActionTree<TagState, RootState> = {
fetch: async ({ commit, rootState }, tag: string): Promise<Array<Status>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>(`/timelines/tag/${encodeURIComponent(tag)}`, { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
@ -112,8 +109,12 @@ const actions: ActionTree<TagState, RootState> = {
commit(MUTATION_TYPES.ARCHIVE_TIMELINE)
}
})
ipcRenderer.on('delete-start-tag-streaming', (_, id: string) => {
commit(MUTATION_TYPES.DELETE_TOOT, id)
})
// @ts-ignore
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
return new Promise((resolve, reject) => {
// eslint-disable-line no-unused-vars
ipcRenderer.send('start-tag-streaming', {
tag: encodeURIComponent(tag),
account: rootState.TimelineSpace.account,
@ -128,6 +129,7 @@ const actions: ActionTree<TagState, RootState> = {
return new Promise(resolve => {
ipcRenderer.removeAllListeners('error-start-tag-streaming')
ipcRenderer.removeAllListeners('update-start-tag-streaming')
ipcRenderer.removeAllListeners('delete-start-tag-streaming')
ipcRenderer.send('stop-tag-streaming')
resolve()
})
@ -137,11 +139,9 @@ const actions: ActionTree<TagState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get<Array<Status>>(`/timelines/tag/${loadPosition.tag}`, { max_id: loadPosition.status.id, limit: 40 })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Status>>(`/timelines/tag/${loadPosition.tag}`, { max_id: loadPosition.status.id, limit: 40 })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -86,12 +86,12 @@ const mutations: MutationTree<HomeState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
[MUTATION_TYPES.DELETE_TOOT]: (state, messageId: string) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
if (toot.reblog !== null && toot.reblog.id === messageId) {
return false
} else {
return toot.id !== message.id
return toot.id !== messageId
}
})
},

View File

@ -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()
})

View File

@ -3,10 +3,10 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface LocalState {
timeline: Array<Status>,
unreadTimeline: Array<Status>,
lazyLoading: boolean,
heading: boolean,
timeline: Array<Status>
unreadTimeline: Array<Status>
lazyLoading: boolean
heading: boolean
filter: string
}
@ -46,22 +46,22 @@ const mutations: MutationTree<LocalState> = {
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = messages
},
[MUTATION_TYPES.MERGE_TIMELINE]: (state) => {
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
state.unreadTimeline = []
},
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = state.timeline.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_TIMELINE]: (state) => {
[MUTATION_TYPES.ARCHIVE_TIMELINE]: state => {
state.timeline = state.timeline.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_TIMELINE]: (state) => {
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.map((toot) => {
state.timeline = state.timeline.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -76,12 +76,12 @@ const mutations: MutationTree<LocalState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === id) {
return false
} else {
return toot.id !== message.id
return toot.id !== id
}
})
},
@ -95,10 +95,7 @@ const mutations: MutationTree<LocalState> = {
const actions: ActionTree<LocalState, RootState> = {
fetchLocalTimeline: async ({ commit, rootState }) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40, local: true })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
@ -108,11 +105,9 @@ const actions: ActionTree<LocalState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40, local: true })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40, local: true })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -3,10 +3,10 @@ import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
import { RootState } from '@/store'
export interface MentionsState {
lazyLoading: boolean,
heading: boolean,
mentions: Array<Notification>,
unreadMentions: Array<Notification>,
lazyLoading: boolean
heading: boolean
mentions: Array<Notification>
unreadMentions: Array<Notification>
filter: string
}
@ -28,6 +28,7 @@ export const MUTATION_TYPES = {
ARCHIVE_MENTIONS: 'archiveMentions',
CLEAR_MENTIONS: 'clearMentions',
UPDATE_TOOT: 'updateToot',
DELETE_TOOT: 'deleteToot',
CHANGE_FILTER: 'changeFilter'
}
@ -48,22 +49,22 @@ const mutations: MutationTree<MentionsState> = {
[MUTATION_TYPES.UPDATE_MENTIONS]: (state, messages: Array<Notification>) => {
state.mentions = messages
},
[MUTATION_TYPES.MERGE_MENTIONS]: (state) => {
[MUTATION_TYPES.MERGE_MENTIONS]: state => {
state.mentions = state.unreadMentions.slice(0, 80).concat(state.mentions)
state.unreadMentions = []
},
[MUTATION_TYPES.INSERT_MENTIONS]: (state, messages: Array<Notification>) => {
state.mentions = state.mentions.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_MENTIONS]: (state) => {
[MUTATION_TYPES.ARCHIVE_MENTIONS]: state => {
state.mentions = state.mentions.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_MENTIONS]: (state) => {
[MUTATION_TYPES.CLEAR_MENTIONS]: state => {
state.mentions = []
state.unreadMentions = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Notification) => {
state.mentions = state.mentions.map((mention) => {
state.mentions = state.mentions.map(mention => {
if (mention.status !== null && mention.status.id === message.id) {
const status = {
status: message
@ -74,6 +75,19 @@ const mutations: MutationTree<MentionsState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
state.mentions = state.mentions.filter(mention => {
if (mention.status) {
if (mention.status.reblog && mention.status.reblog.id === id) {
return false
} else {
return mention.status.id !== id
}
} else {
return true
}
})
},
[MUTATION_TYPES.CHANGE_FILTER]: (state, filter: string) => {
state.filter = filter
}
@ -81,11 +95,11 @@ const mutations: MutationTree<MentionsState> = {
const actions: ActionTree<MentionsState, RootState> = {
fetchMentions: async ({ commit, rootState }): Promise<Array<Notification>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Array<Notification>> = await client.get<Array<Notification>>('/notifications', { limit: 30, exclude_types: ['follow', 'favourite', 'reblog'] })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Notification>> = await client.get<Array<Notification>>('/notifications', {
limit: 30,
exclude_types: ['follow', 'favourite', 'reblog']
})
commit(MUTATION_TYPES.UPDATE_MENTIONS, res.data)
return res.data
},
@ -94,11 +108,9 @@ const actions: ActionTree<MentionsState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get<Array<Notification>>('/notifications', { max_id: lastMention.id, limit: 30, exclude_types: ['follow', 'favourite', 'reblog'] })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Notification>>('/notifications', { max_id: lastMention.id, limit: 30, exclude_types: ['follow', 'favourite', 'reblog'] })
.then(res => {
commit(MUTATION_TYPES.INSERT_MENTIONS, res.data)
return res.data
@ -110,7 +122,7 @@ const actions: ActionTree<MentionsState, RootState> = {
}
const getters: GetterTree<MentionsState, RootState> = {
mentions: (state) => {
mentions: state => {
return state.mentions.filter(mention => mention.type === 'mention')
}
}

View File

@ -27,6 +27,7 @@ export const MUTATION_TYPES = {
MERGE_NOTIFICATIONS: 'mergeNotifications',
INSERT_NOTIFICATIONS: 'insertNotifications',
UPDATE_TOOT: 'updateToot',
DELETE_TOOT: 'deleteToot',
CLEAR_NOTIFICATIONS: 'clearNotifications',
ARCHIVE_NOTIFICATIONS: 'archiveNotifications',
CHANGE_FILTER: 'changeFilter'
@ -70,6 +71,19 @@ const mutations: MutationTree<NotificationsState> = {
}
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, id: string) => {
state.notifications = state.notifications.filter(notification => {
if (notification.status) {
if (notification.status.reblog && notification.status.reblog.id === id) {
return false
} else {
return notification.status.id !== id
}
} else {
return true
}
})
},
[MUTATION_TYPES.CLEAR_NOTIFICATIONS]: state => {
state.notifications = []
},

View File

@ -76,12 +76,12 @@ const mutations: MutationTree<PublicState> = {
}
})
},
[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
}
})
},