Merge pull request #928 from h3poteto/iss-630

refs #630 Upgrade megalodon and fix id type
This commit is contained in:
AkiraFukushima 2019-05-28 00:38:39 +09:00 committed by GitHub
commit 6247e5ad7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 150 additions and 226 deletions

22
package-lock.json generated
View File

@ -13167,9 +13167,9 @@
"dev": true
},
"megalodon": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/megalodon/-/megalodon-0.6.3.tgz",
"integrity": "sha512-rxh9Kbbwm9Hnn/e8xdzH2Fw5kD/TamgyGFEzOcsnKCqF4iI2qHuojCBm7KeWohgRlwJ9oq7QYVReEVTipqI8kQ==",
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/megalodon/-/megalodon-0.7.0.tgz",
"integrity": "sha512-mpRXvUYvJ9D1A/CUgecUok/vjSbd9nV5zzOjt5QdzdiFKtv3ETJC7a5zk9X2aXSFawUcgpaZwyVLxfVO4n6pyg==",
"requires": {
"@types/oauth": "0.9.1",
"@types/request": "2.48.1",
@ -13177,14 +13177,14 @@
"axios": "0.18.0",
"oauth": "0.9.15",
"request": "2.88.0",
"typescript": "2.9.2",
"typescript": "3.4.5",
"websocket": "1.0.28"
},
"dependencies": {
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w=="
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw=="
}
}
},
@ -21120,7 +21120,7 @@
"integrity": "sha512-00y/20/80P7H4bCYkzuuvvfDvh+dgtXi5kzDf3UcZwN6boTYaKvsrtZ5lIYm1Gsg48siMErd9M4zjSYfYFHTrA==",
"requires": {
"debug": "2.6.9",
"nan": "2.13.2",
"nan": "2.14.0",
"typedarray-to-buffer": "3.1.5",
"yaeti": "0.0.6"
},
@ -21134,9 +21134,9 @@
}
},
"nan": {
"version": "2.13.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz",
"integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw=="
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
}
}
},

View File

@ -171,7 +171,7 @@
"i18next": "^12.1.0",
"i18next-sync-fs-backend": "^1.1.0",
"lodash": "^4.17.11",
"megalodon": "0.6.3",
"megalodon": "0.7.0",
"moment": "^2.21.0",
"mousetrap": "^1.6.2",
"nedb": "^1.8.0",

View File

@ -94,6 +94,9 @@ const contentsStore = {
Local: LocalStore,
Public: PublicStore,
Mentions: MentionStore
},
actions: {
changeLoading: jest.fn()
}
}
@ -168,7 +171,7 @@ describe('TimelineSpace', () => {
}
})
it('should be detected', async () => {
(Mastodon.get as any).mockResolvedValue(mockedResponse)
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/detectPleroma')
expect(store.state.TimelineSpace.pleroma).toEqual(true)
expect(store.state.TimelineSpace.useWebsocket).toEqual(true)
@ -203,7 +206,7 @@ describe('TimelineSpace', () => {
}
})
it('should be detected', async () => {
(Mastodon.get as any).mockResolvedValue(mockedResponse)
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/detectPleroma')
expect(store.state.TimelineSpace.pleroma).toEqual(false)
expect(store.state.TimelineSpace.useWebsocket).toEqual(false)
@ -229,17 +232,14 @@ describe('TimelineSpace', () => {
visible_in_picker: true
}
mockedResponse = {
data: [
emacsEmoji,
rubyEmoji
],
data: [emacsEmoji, rubyEmoji],
status: 200,
statusText: 'OK',
headers: {}
}
})
it('should be updated', async () => {
(Mastodon.get as any).mockResolvedValue(mockedResponse)
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/fetchEmojis', {})
expect(store.state.TimelineSpace.emojis).toEqual([
{
@ -249,7 +249,8 @@ describe('TimelineSpace', () => {
{
image: 'http://example.com/ruby',
name: ':ruby:'
}])
}
])
})
})
@ -264,7 +265,7 @@ describe('TimelineSpace', () => {
}
})
it('should be updated', async () => {
(Mastodon.get as any).mockResolvedValue(mockedResponse)
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/fetchInstance', {})
expect(store.state.TimelineSpace.tootMax).toEqual(5000)
})

View File

@ -7,7 +7,7 @@ import Home, { HomeState } from '@/store/TimelineSpace/Contents/Home'
jest.mock('megalodon')
const account: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -28,7 +28,7 @@ const account: Account = {
bot: false
}
const status1: Status = {
id: 1,
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -58,7 +58,7 @@ const status1: Status = {
pinned: null
}
const status2: Status = {
id: 2,
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -141,9 +141,7 @@ describe('Home', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<Status[]>>(resolve => {
const res: Response<Status[]> = {
data: [
status1
],
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
@ -155,12 +153,8 @@ describe('Home', () => {
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('Home/fetchTimeline')
expect(statuses).toEqual([
status1
])
expect(store.state.Home.timeline).toEqual([
status1
])
expect(statuses).toEqual([status1])
expect(store.state.Home.timeline).toEqual([status1])
})
})
@ -184,9 +178,7 @@ describe('Home', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<[Status]>>(resolve => {
const res: Response<[Status]> = {
data: [
status2
],
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
@ -198,10 +190,7 @@ describe('Home', () => {
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Home/lazyFetchTimeline', { id: 20 })
expect(store.state.Home.lazyLoading).toEqual(false)
expect(store.state.Home.timeline).toEqual([
status1,
status2
])
expect(store.state.Home.timeline).toEqual([status1, status2])
})
})
})

View File

@ -7,7 +7,7 @@ import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions'
jest.mock('megalodon')
const account: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -29,7 +29,7 @@ const account: Account = {
}
const status: Status = {
id: 1,
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -62,7 +62,7 @@ const status: Status = {
const mention: Notification = {
account: account,
created_at: '2019-03-26T21:40:32',
id: 1,
id: '1',
status: status,
type: 'mention'
}
@ -70,7 +70,7 @@ const mention: Notification = {
const reblog: Notification = {
account: account,
created_at: '2019-03-26T21:40:32',
id: 2,
id: '2',
status: status,
type: 'reblog'
}
@ -78,7 +78,7 @@ const reblog: Notification = {
const favourite: Notification = {
account: account,
created_at: '2019-03-26T21:40:32',
id: 3,
id: '3',
status: status,
type: 'favourite'
}
@ -86,7 +86,7 @@ const favourite: Notification = {
const follow: Notification = {
account: account,
created_at: '2019-03-26T21:40:32',
id: 4,
id: '4',
status: null,
type: 'follow'
}
@ -142,12 +142,7 @@ describe('Mentions', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<Notification[]>>(resolve => {
const res: Response<Notification[]> = {
data: [
mention,
reblog,
favourite,
follow
],
data: [mention, reblog, favourite, follow],
status: 200,
statusText: 'OK',
headers: {}
@ -159,12 +154,7 @@ describe('Mentions', () => {
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Mentions/fetchMentions')
expect(store.state.Mentions.mentions).toEqual([
mention,
reblog,
favourite,
follow
])
expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow])
})
})
@ -193,10 +183,7 @@ describe('Mentions', () => {
return {
lazyLoading: false,
heading: true,
mentions: [
mention,
reblog
],
mentions: [mention, reblog],
unreadMentions: [],
filter: ''
}
@ -207,10 +194,7 @@ describe('Mentions', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<Notification[]>>(resolve => {
const res: Response<Notification[]> = {
data: [
favourite,
follow
],
data: [favourite, follow],
status: 200,
statusText: 'OK',
headers: {}
@ -222,12 +206,7 @@ describe('Mentions', () => {
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Mentions/lazyFetchMentions', { id: 1 })
expect(store.state.Mentions.mentions).toEqual([
mention,
reblog,
favourite,
follow
])
expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow])
expect(store.state.Mentions.lazyLoading).toEqual(false)
})
})
@ -239,12 +218,7 @@ describe('Mentions', () => {
return {
lazyLoading: false,
heading: true,
mentions: [
mention,
favourite,
reblog,
follow
],
mentions: [mention, favourite, reblog, follow],
unreadMentions: [],
filter: ''
}
@ -252,9 +226,7 @@ describe('Mentions', () => {
})
it('should return only mentions', () => {
const mentions = store.getters['Mentions/mentions']
expect(mentions).toEqual([
mention
])
expect(mentions).toEqual([mention])
})
})
})

View File

@ -7,7 +7,7 @@ import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/
jest.mock('megalodon')
const list: List = {
id: 1,
id: '1',
title: 'example'
}

View File

@ -7,7 +7,7 @@ import AddListMember, { AddListMemberState } from '@/store/TimelineSpace/Modals/
jest.mock('megalodon')
const account: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -83,9 +83,7 @@ describe('AddListMember', () => {
get: () => {
return new Promise<Response<Account[]>>(resolve => {
const res: Response<Account[]> = {
data: [
account
],
data: [account],
status: 200,
statusText: 'OK',
headers: {}
@ -97,9 +95,7 @@ describe('AddListMember', () => {
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('AddListMember/search', 'akira')
expect(store.state.AddListMember.accounts).toEqual([
account
])
expect(store.state.AddListMember.accounts).toEqual([account])
})
})

View File

@ -7,7 +7,7 @@ import ListMembership, { ListMembershipState } from '@/store/TimelineSpace/Modal
jest.mock('megalodon')
const account: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -29,12 +29,12 @@ const account: Account = {
}
const list1: List = {
id: 1,
id: '1',
title: 'list1'
}
const list2: List = {
id: 2,
id: '2',
title: 'list2'
}
@ -86,10 +86,7 @@ describe('ListMembership', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<List[]>>(resolve => {
const res: Response<List[]> = {
data: [
list1,
list2
],
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
@ -100,9 +97,9 @@ describe('ListMembership', () => {
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('ListMembership/fetchListMembership', {
id: 5
id: '5'
})
expect(store.state.ListMembership.belongToLists).toEqual([1, 2])
expect(store.state.ListMembership.belongToLists).toEqual(['1', '2'])
})
})
@ -112,10 +109,7 @@ describe('ListMembership', () => {
get: (_path: string, _params: object) => {
return new Promise<Response<List[]>>(resolve => {
const res: Response<List[]> = {
data: [
list1,
list2
],
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
@ -126,10 +120,7 @@ describe('ListMembership', () => {
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('ListMembership/fetchLists')
expect(store.state.ListMembership.lists).toEqual([
list1,
list2
])
expect(store.state.ListMembership.lists).toEqual([list1, list2])
})
})
@ -140,9 +131,7 @@ describe('ListMembership', () => {
modalOpen: false,
account: account,
lists: [],
belongToLists: [
list2
]
belongToLists: [list2]
}
}
})

View File

@ -9,12 +9,12 @@ import LocalTag from '~/src/types/localTag'
jest.mock('megalodon')
const list1: List = {
id: 1,
id: '1',
title: 'example1'
}
const list2: List = {
id: 2,
id: '2',
title: 'example2'
}

View File

@ -2,7 +2,7 @@ import { Account, Status, Application } from 'megalodon'
import Home, { HomeState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Home'
const account: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -23,7 +23,7 @@ const account: Account = {
bot: false
}
const status1: Status = {
id: 1,
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -53,7 +53,7 @@ const status1: Status = {
pinned: null
}
const status2: Status = {
id: 2,
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -212,7 +212,7 @@ describe('TimelineSpace/Contents/Home', () => {
})
describe('message is reblogged', () => {
const rebloggedStatus: Status = {
id: 3,
id: '3',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
@ -285,7 +285,7 @@ describe('TimelineSpace/Contents/Home', () => {
describe('message is reblogged', () => {
beforeEach(() => {
const rebloggedStatus: Status = {
id: 3,
id: '3',
uri: 'http://example.com',
url: 'http://example.com',
account: account,

View File

@ -2,7 +2,7 @@ import { Account, Notification, Status, Application } from 'megalodon'
import Mentions, { MentionsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Mentions'
const account1: Account = {
id: 1,
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
@ -24,7 +24,7 @@ const account1: Account = {
}
const account2: Account = {
id: 2,
id: '2',
username: 'h3poteto',
acct: 'h3poteto@mstdn.io',
display_name: 'h3poteto',
@ -46,7 +46,7 @@ const account2: Account = {
}
const status: Status = {
id: 1,
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
@ -77,7 +77,7 @@ const status: Status = {
}
const notification1: Notification = {
id: 1,
id: '1',
account: account2,
status: status,
type: 'favourite',
@ -85,7 +85,7 @@ const notification1: Notification = {
}
const notification2: Notification = {
id: 2,
id: '2',
account: account2,
status: status,
type: 'reblog',

View File

@ -56,15 +56,15 @@ describe('TimelineSpace/Modals/Jump', () => {
describe('updateListChannel', () => {
it('should be updated', () => {
const admin: List = {
id: 0,
id: '0',
title: 'admin'
}
const engineer: List = {
id: 1,
id: '1',
title: 'engineer'
}
const designer: List = {
id: 2,
id: '2',
title: 'designer'
}
const channelList = [admin, engineer, designer]

View File

@ -607,7 +607,7 @@ ipcMain.on('stop-public-streaming', () => {
let listStreaming: StreamingManager | null = null
type ListID = {
listID: number
listID: string
}
ipcMain.on('start-list-streaming', (event: Event, obj: ListID & StreamingSetting) => {

View File

@ -116,7 +116,7 @@ export default {
return false
}
this.$store.dispatch('TimelineSpace/Modals/NewToot/openModal')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/uploadImage', file).catch(() => {
this.$message({
message: this.$t('message.attach_error'),

View File

@ -208,7 +208,7 @@ export default {
methods: {
close() {
this.filteredAccount = []
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
},
async toot() {
@ -277,7 +277,7 @@ export default {
this.updateImage(file)
},
updateImage(file) {
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/uploadImage', file).catch(() => {
this.$message({
message: this.$t('message.attach_error'),

View File

@ -4,7 +4,7 @@ import { Module, MutationTree } from 'vuex'
import { RootState } from '@/store'
export interface SettingsState {
accountID: number | null
accountID: string | null
}
const state = (): SettingsState => ({
@ -16,14 +16,14 @@ export const MUTATION_TYPES = {
}
const mutations: MutationTree<SettingsState> = {
[MUTATION_TYPES.CHANGE_ACCOUNT_ID]: (state, id: number) => {
[MUTATION_TYPES.CHANGE_ACCOUNT_ID]: (state, id: string) => {
state.accountID = id
}
}
export interface SettingsModuleState extends SettingsState {
General: GeneralState,
Timeline: TimelineState,
General: GeneralState
Timeline: TimelineState
}
const Settings: Module<SettingsState, RootState> = {

View File

@ -104,7 +104,7 @@ const mutations: MutationTree<TimelineSpaceState> = {
}
const actions: ActionTree<TimelineSpaceState, RootState> = {
initLoad: async ({ dispatch, commit }, accountId: number): Promise<Account> => {
initLoad: async ({ dispatch, commit }, accountId: string): Promise<Account> => {
commit(MUTATION_TYPES.CHANGE_LOADING, true)
dispatch('watchShortcutEvents')
const account = await dispatch('localAccount', accountId).catch(_ => {

View File

@ -5,10 +5,10 @@ import { RootState } from '@/store'
import LocalAccount from '~/src/types/localAccount'
export interface FavouritesState {
favourites: Array<Status>,
lazyLoading: boolean,
filter: string,
maxId: number | null
favourites: Array<Status>
lazyLoading: boolean
filter: string
maxId: string | null
}
const state = (): FavouritesState => ({
@ -36,7 +36,7 @@ const mutations: MutationTree<FavouritesState> = {
state.favourites = state.favourites.concat(favourites)
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.favourites = state.favourites.map((toot) => {
state.favourites = state.favourites.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -52,7 +52,7 @@ const mutations: MutationTree<FavouritesState> = {
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.favourites = state.favourites.filter((toot) => {
state.favourites = state.favourites.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
@ -66,24 +66,21 @@ const mutations: MutationTree<FavouritesState> = {
[MUTATION_TYPES.CHANGE_FILTER]: (state, filter: string) => {
state.filter = filter
},
[MUTATION_TYPES.CHANGE_MAX_ID]: (state, id: number | null) => {
[MUTATION_TYPES.CHANGE_MAX_ID]: (state, id: string | null) => {
state.maxId = id
}
}
const actions: ActionTree<FavouritesState, RootState> = {
fetchFavourites: async ({ commit }, account: LocalAccount): Promise<Array<Status>> => {
const client = new Mastodon(
account.accessToken!,
account.baseURL + '/api/v1'
)
const client = new Mastodon(account.accessToken!, account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { limit: 40 })
commit(MUTATION_TYPES.UPDATE_FAVOURITES, res.data)
// Parse link header
try {
const link = parse(res.headers.link)
if (link !== null) {
commit(MUTATION_TYPES.CHANGE_MAX_ID, parseInt(link.next.max_id))
commit(MUTATION_TYPES.CHANGE_MAX_ID, link.next.max_id)
} else {
commit(MUTATION_TYPES.CHANGE_MAX_ID, null)
}
@ -101,20 +98,16 @@ const actions: ActionTree<FavouritesState, 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'
)
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { max_id: state.maxId, limit: 40 })
.finally(() => {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
})
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { max_id: state.maxId, limit: 40 }).finally(() => {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
})
commit(MUTATION_TYPES.INSERT_FAVOURITES, res.data)
// Parse link header
try {
const link = parse(res.headers.link)
if (link !== null) {
commit(MUTATION_TYPES.CHANGE_MAX_ID, parseInt(link.next.max_id))
commit(MUTATION_TYPES.CHANGE_MAX_ID, link.next.max_id)
} else {
commit(MUTATION_TYPES.CHANGE_MAX_ID, null)
}

View File

@ -22,11 +22,8 @@ const mutations: MutationTree<EditState> = {
}
const actions: ActionTree<EditState, RootState> = {
fetchMembers: async ({ commit, rootState }, listId: number): Promise<Array<Account>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
fetchMembers: async ({ commit, rootState }, listId: string): Promise<Array<Account>> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/lists/${listId}/accounts`, {
limit: 0
})
@ -34,10 +31,7 @@ const actions: ActionTree<EditState, RootState> = {
return res.data
},
removeAccount: async ({ rootState }, remove: RemoveAccountFromList): Promise<{}> => {
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')
return client.del<{}>(`/lists/${remove.listId}/accounts`, {
account_ids: [remove.account.id]
})

View File

@ -5,10 +5,10 @@ import { RootState } from '@/store'
import { LoadPositionWithList } from '@/types/loadPosition'
export interface ShowState {
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<ShowState> = {
[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) {
@ -79,7 +79,7 @@ const mutations: MutationTree<ShowState> = {
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
@ -96,16 +96,13 @@ const mutations: MutationTree<ShowState> = {
}
const actions: ActionTree<ShowState, RootState> = {
fetchTimeline: async ({ commit, rootState }, listID: number): Promise<Array<Status>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
fetchTimeline: async ({ commit, rootState }, listID: string): Promise<Array<Status>> => {
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/list/${listID}`, { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
},
startStreaming: ({ state, commit, rootState }, listID: number) => {
startStreaming: ({ state, commit, rootState }, listID: string) => {
ipcRenderer.on('update-start-list-streaming', (_, update: Status) => {
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
if (state.heading && Math.random() > 0.8) {
@ -113,7 +110,8 @@ const actions: ActionTree<ShowState, RootState> = {
}
})
// @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-list-streaming', {
listID: listID,
account: rootState.TimelineSpace.account,
@ -137,11 +135,9 @@ const actions: ActionTree<ShowState, 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/list/${loadPosition.list_id}`, { 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/list/${loadPosition.list_id}`, { max_id: loadPosition.status.id, limit: 40 })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -42,7 +42,7 @@ const mutations: MutationTree<AccountProfileState> = {
}
const actions: ActionTree<AccountProfileState, RootState> = {
fetchAccount: async ({ rootState }, accountID: number): Promise<Account> => {
fetchAccount: async ({ rootState }, accountID: string): Promise<Account> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Account> = await client.get<Account>(`/accounts/${accountID}`)
return res.data

View File

@ -34,7 +34,7 @@ const mutations: MutationTree<HeaderMenuState> = {
}
const actions: ActionTree<HeaderMenuState, RootState> = {
fetchList: async ({ commit, rootState }, listID: number): Promise<List> => {
fetchList: async ({ commit, rootState }, listID: string): Promise<List> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<List> = await client.get<List>(`/lists/${listID}`)
commit(MUTATION_TYPES.UPDATE_TITLE, `#${res.data.title}`)

View File

@ -3,9 +3,9 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface AddListMemberState {
modalOpen: boolean,
accounts: Array<Account>,
targetListId: number | null
modalOpen: boolean
accounts: Array<Account>
targetListId: string | null
}
const state = (): AddListMemberState => ({
@ -27,7 +27,7 @@ const mutations: MutationTree<AddListMemberState> = {
[MUTATION_TYPES.UPDATE_ACCOUNTS]: (state, accounts: Array<Account>) => {
state.accounts = accounts
},
[MUTATION_TYPES.SET_LIST_ID]: (state, id: number) => {
[MUTATION_TYPES.SET_LIST_ID]: (state, id: string) => {
state.targetListId = id
}
}
@ -37,10 +37,7 @@ const actions: ActionTree<AddListMemberState, RootState> = {
commit(MUTATION_TYPES.CHANGE_MODAL, value)
},
search: async ({ commit, rootState }, name: string): Promise<Array<Account>> => {
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<Account>> = await client.get<Array<Account>>('/accounts/search', {
q: name,
following: true
@ -49,10 +46,7 @@ const actions: ActionTree<AddListMemberState, RootState> = {
return res.data
},
add: async ({ state, rootState }, account: Account): Promise<{}> => {
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<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, {
account_ids: [account.id]
})

View File

@ -16,7 +16,7 @@ import {
} from '@/errors/validations'
type MediaDescription = {
id: number
id: string
description: string
}
@ -27,10 +27,10 @@ export interface NewTootState {
replyToMessage: Status | null
blockSubmit: boolean
attachedMedias: Array<Attachment>
mediaDescriptions: { [key: number]: string | null }
mediaDescriptions: { [key: string]: string | null }
visibility: number
sensitive: boolean
attachedMediaId: number
attachedMediaCount: number
pinedHashtag: boolean
hashtags: Array<Tag>
loading: boolean
@ -50,7 +50,7 @@ const state = (): NewTootState => ({
mediaDescriptions: {},
visibility: Visibility.Public.value,
sensitive: false,
attachedMediaId: 0,
attachedMediaCount: 0,
pinedHashtag: false,
hashtags: [],
loading: false
@ -70,7 +70,7 @@ export const MUTATION_TYPES = {
REMOVE_MEDIA_DESCRIPTION: 'removeMediaDescription',
CHANGE_VISIBILITY_VALUE: 'changeVisibilityValue',
CHANGE_SENSITIVE: 'changeSensitive',
UPDATE_MEDIA_ID: 'updateMediaId',
UPDATE_MEDIA_COUNT: 'updateMediaCount',
CHANGE_PINED_HASHTAG: 'changePinedHashtag',
UPDATE_HASHTAGS: 'updateHashtags',
CHANGE_LOADING: 'changeLoading'
@ -107,7 +107,7 @@ const mutations: MutationTree<NewTootState> = {
[MUTATION_TYPES.CLEAR_MEDIA_DESCRIPTIONS]: state => {
state.mediaDescriptions = {}
},
[MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION]: (state, id: number) => {
[MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION]: (state, id: string) => {
const descriptions = state.mediaDescriptions
delete descriptions[id]
state.mediaDescriptions = descriptions
@ -124,8 +124,8 @@ const mutations: MutationTree<NewTootState> = {
[MUTATION_TYPES.CHANGE_SENSITIVE]: (state, value: boolean) => {
state.sensitive = value
},
[MUTATION_TYPES.UPDATE_MEDIA_ID]: (state, value: number) => {
state.attachedMediaId = value
[MUTATION_TYPES.UPDATE_MEDIA_COUNT]: (state, count: number) => {
state.attachedMediaCount = count
},
[MUTATION_TYPES.CHANGE_PINED_HASHTAG]: (state, value: boolean) => {
state.pinedHashtag = value
@ -286,19 +286,19 @@ const actions: ActionTree<NewTootState, RootState> = {
throw err
})
},
incrementMediaId: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, state.attachedMediaId + 1)
incrementMediaCount: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount + 1)
},
decrementMediaId: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, state.attachedMediaId - 1)
decrementMediaCount: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount - 1)
},
resetMediaId: ({ commit }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, 0)
resetMediaCount: ({ commit }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, 0)
},
removeMedia: ({ commit, dispatch }, media: Attachment) => {
commit(MUTATION_TYPES.REMOVE_MEDIA, media)
commit(MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION, media.id)
dispatch('decrementMediaId')
dispatch('decrementMediaCount')
},
updateHashtags: ({ commit, state }, tags: Array<Tag>) => {
if (state.pinedHashtag && tags.length > 0) {

View File

@ -9,7 +9,7 @@ export interface LoadPositionWithAccount extends LoadPosition {
}
export interface LoadPositionWithList extends LoadPosition {
list_id: number
list_id: string
}
export interface LoadPositionWithTag extends LoadPosition {

View File

@ -1,6 +1,6 @@
import { Account } from 'megalodon'
export interface RemoveAccountFromList {
account: Account,
listId: number
account: Account
listId: string
}

View File

@ -1,13 +1,13 @@
export default interface LocalAccount {
_id?: string,
baseURL: string,
domain: string,
clientId: string,
clientSecret: string,
accessToken: string | null,
refreshToken: string | null,
username: string | null,
accountId: number | null,
avatar: string | null,
_id?: string
baseURL: string
domain: string
clientId: string
clientSecret: string
accessToken: string | null
refreshToken: string | null
username: string | null
accountId: string | null
avatar: string | null
order: number
}