2019-04-10 17:15:12 +02:00
|
|
|
import Mastodon, { Status } from 'megalodon'
|
|
|
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
|
|
|
import { RootState } from '@/store'
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type ReportState = {
|
|
|
|
modalOpen: boolean
|
2019-04-10 17:15:12 +02:00
|
|
|
message: Status | null
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = (): ReportState => ({
|
|
|
|
modalOpen: false,
|
|
|
|
message: null
|
|
|
|
})
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
CHANGE_MODAL_OPEN: 'changeModalOpen',
|
|
|
|
CHANGE_MESSAGE: 'changeMessage'
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<ReportState> = {
|
|
|
|
[MUTATION_TYPES.CHANGE_MODAL_OPEN]: (state, value: boolean) => {
|
|
|
|
state.modalOpen = value
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CHANGE_MESSAGE]: (state, message: Status) => {
|
|
|
|
state.message = message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions: ActionTree<ReportState, RootState> = {
|
|
|
|
openReport: ({ commit }, message: Status) => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MESSAGE, message)
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MODAL_OPEN, true)
|
|
|
|
},
|
|
|
|
submit: async ({ rootState }, { account_id, status_id, comment }) => {
|
2019-10-27 06:41:03 +01:00
|
|
|
const client = new Mastodon(
|
|
|
|
rootState.TimelineSpace.account.accessToken!,
|
|
|
|
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
|
|
|
rootState.App.userAgent,
|
|
|
|
rootState.App.proxyConfiguration
|
|
|
|
)
|
2019-04-10 17:15:12 +02:00
|
|
|
return client.post<{}>(`/reports`, {
|
|
|
|
account_id: account_id,
|
|
|
|
status_ids: [status_id],
|
|
|
|
comment: comment
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
actions: actions
|
|
|
|
} as Module<ReportState, RootState>
|