/
MuteConfirm.ts
59 lines (52 loc) · 1.68 KB
/
MuteConfirm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Mastodon, { Account, Response, Relationship } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export type MuteConfirmState = {
modalOpen: boolean
account: Account | null
}
const state = (): MuteConfirmState => ({
modalOpen: false,
account: null
})
export const MUTATION_TYPES = {
CHANGE_MODAL: 'changeModal',
CHANGE_ACCOUNT: 'changeAccount'
}
const mutations: MutationTree<MuteConfirmState> = {
[MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => {
state.modalOpen = value
},
[MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Account) => {
state.account = account
}
}
const actions: ActionTree<MuteConfirmState, RootState> = {
changeModal: ({ commit }, value: boolean) => {
commit(MUTATION_TYPES.CHANGE_MODAL, value)
},
changeAccount: ({ commit }, account: Account) => {
commit(MUTATION_TYPES.CHANGE_ACCOUNT, account)
},
submit: async ({ state, rootState, dispatch }, notify: boolean) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1',
rootState.App.userAgent,
rootState.App.proxyConfiguration
)
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${state.account!.id}/mute`, {
notifications: notify
})
// Reload relationship
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/fetchRelationship', state.account, { root: true })
return res.data
}
}
const MuteConfirm: Module<MuteConfirmState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,
actions: actions
}
export default MuteConfirm