Merge pull request #868 from h3poteto/iss-850

refs #850 Replace Toot with typescript
This commit is contained in:
AkiraFukushima 2019-04-06 23:36:01 +09:00 committed by GitHub
commit 9cdd27366e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 74 deletions

View File

@ -1,74 +0,0 @@
import Mastodon from 'megalodon'
import { ipcRenderer } from 'electron'
const Toot = {
namespaced: true,
state: {},
mutations: {},
actions: {
reblog ({ rootState }, message) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/reblog`)
.then(res => {
// API returns new status when reblog.
// Reblog target status is in the data.reblog.
// So I send data.reblog as status for update local timeline.
ipcRenderer.send('fav-rt-action-sound')
return res.data.reblog
})
},
unreblog ({ rootState }, message) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/unreblog`)
.then(res => {
return res.data
})
},
addFavourite ({ rootState }, message) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/favourite`)
.then(res => {
ipcRenderer.send('fav-rt-action-sound')
return res.data
})
},
removeFavourite ({ rootState }, message) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/unfavourite`)
.then(res => {
return res.data
})
},
deleteToot ({ rootState }, message) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.del(`/statuses/${message.id}`)
.then(() => {
return message
})
},
block ({ rootState }, account) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/block`)
}
}
}
export default Toot

View File

@ -0,0 +1,70 @@
import Mastodon, { Response, Status, Account } from 'megalodon'
import { ipcRenderer } from 'electron'
import { Module, ActionTree } from 'vuex'
export interface TootState {}
const state = (): TootState => ({})
const actions: ActionTree<TootState, any> = {
reblog: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/reblog`)
// API returns new status when reblog.
// Reblog target status is in the data.reblog.
// So I send data.reblog as status for update local timeline.
ipcRenderer.send('fav-rt-action-sound')
return res.data.reblog
},
unreblog: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unreblog`)
return res.data
},
addFavourite: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/favourite`)
ipcRenderer.send('fav-rt-action-sound')
return res.data
},
removeFavourite: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unfavourite`)
return res.data
},
deleteToot: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
await client.del(`/statuses/${message.id}`)
return message
},
block: async ({ rootState }, account: Account) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/block`)
}
}
const Toot: Module<TootState, any> = {
namespaced: true,
state: state,
actions: actions
}
export default Toot