2020-03-15 09:47:56 +01:00
|
|
|
import generator, { Entity } from 'megalodon'
|
2019-04-15 13:47:05 +02:00
|
|
|
import Visibility, { VisibilityType } from '~/src/constants/visibility'
|
2019-04-10 17:06:43 +02:00
|
|
|
import TootStatus, { StatusState } from './NewToot/Status'
|
|
|
|
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
|
|
|
|
import { RootState } from '@/store'
|
2019-05-07 16:22:01 +02:00
|
|
|
import AxiosLoading from '@/utils/axiosLoading'
|
2019-05-14 16:33:28 +02:00
|
|
|
import {
|
|
|
|
NewTootModalOpen,
|
|
|
|
NewTootBlockSubmit,
|
|
|
|
NewTootTootLength,
|
|
|
|
NewTootAttachLength,
|
|
|
|
NewTootMediaDescription,
|
2019-07-20 15:21:40 +02:00
|
|
|
NewTootPollInvalid,
|
2019-05-14 16:33:28 +02:00
|
|
|
NewTootUnknownType,
|
|
|
|
AuthenticationError
|
|
|
|
} from '@/errors/validations'
|
2019-12-04 14:56:38 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
|
|
|
|
|
|
|
const win = window as MyWindow
|
2019-05-13 17:25:09 +02:00
|
|
|
|
|
|
|
type MediaDescription = {
|
2019-05-27 15:56:54 +02:00
|
|
|
id: string
|
2019-05-13 17:25:09 +02:00
|
|
|
description: string
|
|
|
|
}
|
2019-04-10 17:06:43 +02:00
|
|
|
|
2019-07-16 16:56:00 +02:00
|
|
|
type TootForm = {
|
|
|
|
status: string
|
|
|
|
spoiler: string
|
|
|
|
polls: Array<string>
|
2019-07-16 18:36:19 +02:00
|
|
|
pollExpireSeconds: number
|
2019-07-16 16:56:00 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type NewTootState = {
|
2019-05-07 16:22:01 +02:00
|
|
|
modalOpen: boolean
|
|
|
|
initialStatus: string
|
|
|
|
initialSpoiler: string
|
2020-03-15 09:47:56 +01:00
|
|
|
replyToMessage: Entity.Status | null
|
2019-05-07 16:22:01 +02:00
|
|
|
blockSubmit: boolean
|
2020-03-15 09:47:56 +01:00
|
|
|
attachedMedias: Array<Entity.Attachment>
|
2019-05-27 15:56:54 +02:00
|
|
|
mediaDescriptions: { [key: string]: string | null }
|
2019-05-07 16:22:01 +02:00
|
|
|
visibility: number
|
|
|
|
sensitive: boolean
|
2019-05-27 15:56:54 +02:00
|
|
|
attachedMediaCount: number
|
2019-05-07 16:22:01 +02:00
|
|
|
pinedHashtag: boolean
|
2020-03-15 09:47:56 +01:00
|
|
|
hashtags: Array<Entity.Tag>
|
2019-05-07 16:22:01 +02:00
|
|
|
loading: boolean
|
2019-04-10 17:06:43 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
type NewTootModule = {
|
2019-04-10 17:06:43 +02:00
|
|
|
Status: StatusState
|
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type NewTootModuleState = NewTootModule & NewTootState
|
|
|
|
|
2019-04-10 17:06:43 +02:00
|
|
|
const state = (): NewTootState => ({
|
|
|
|
modalOpen: false,
|
|
|
|
initialStatus: '',
|
|
|
|
initialSpoiler: '',
|
|
|
|
replyToMessage: null,
|
|
|
|
blockSubmit: false,
|
|
|
|
attachedMedias: [],
|
2019-05-13 17:25:09 +02:00
|
|
|
mediaDescriptions: {},
|
2019-04-10 17:06:43 +02:00
|
|
|
visibility: Visibility.Public.value,
|
|
|
|
sensitive: false,
|
2019-05-27 15:56:54 +02:00
|
|
|
attachedMediaCount: 0,
|
2019-04-10 17:06:43 +02:00
|
|
|
pinedHashtag: false,
|
2019-05-07 16:22:01 +02:00
|
|
|
hashtags: [],
|
|
|
|
loading: false
|
2019-04-10 17:06:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
CHANGE_MODAL: 'changeModal',
|
|
|
|
SET_REPLY_TO: 'setReplyTo',
|
|
|
|
UPDATE_INITIAL_STATUS: 'updateInitialStatus',
|
|
|
|
UPDATE_INITIAL_SPOILER: 'updateInitialSpoiler',
|
|
|
|
CHANGE_BLOCK_SUBMIT: 'changeBlockSubmit',
|
|
|
|
APPEND_ATTACHED_MEDIAS: 'appendAttachedMedias',
|
|
|
|
CLEAR_ATTACHED_MEDIAS: 'clearAttachedMedias',
|
|
|
|
REMOVE_MEDIA: 'removeMedia',
|
2019-05-13 17:25:09 +02:00
|
|
|
UPDATE_MEDIA_DESCRIPTION: 'updateMediaDescription',
|
|
|
|
CLEAR_MEDIA_DESCRIPTIONS: 'clearMediaDescriptions',
|
|
|
|
REMOVE_MEDIA_DESCRIPTION: 'removeMediaDescription',
|
2019-04-10 17:06:43 +02:00
|
|
|
CHANGE_VISIBILITY_VALUE: 'changeVisibilityValue',
|
|
|
|
CHANGE_SENSITIVE: 'changeSensitive',
|
2019-05-27 15:56:54 +02:00
|
|
|
UPDATE_MEDIA_COUNT: 'updateMediaCount',
|
2019-04-10 17:06:43 +02:00
|
|
|
CHANGE_PINED_HASHTAG: 'changePinedHashtag',
|
2019-05-07 16:22:01 +02:00
|
|
|
UPDATE_HASHTAGS: 'updateHashtags',
|
|
|
|
CHANGE_LOADING: 'changeLoading'
|
2019-04-10 17:06:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<NewTootState> = {
|
|
|
|
[MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => {
|
|
|
|
state.modalOpen = value
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
[MUTATION_TYPES.SET_REPLY_TO]: (state, message: Entity.Status) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
state.replyToMessage = message
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.UPDATE_INITIAL_STATUS]: (state, status: string) => {
|
|
|
|
state.initialStatus = status
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.UPDATE_INITIAL_SPOILER]: (state, cw: string) => {
|
|
|
|
state.initialSpoiler = cw
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CHANGE_BLOCK_SUBMIT]: (state, value: boolean) => {
|
|
|
|
state.blockSubmit = value
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
[MUTATION_TYPES.APPEND_ATTACHED_MEDIAS]: (state, media: Entity.Attachment) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
state.attachedMedias = state.attachedMedias.concat([media])
|
|
|
|
},
|
2019-05-07 16:22:01 +02:00
|
|
|
[MUTATION_TYPES.CLEAR_ATTACHED_MEDIAS]: state => {
|
2019-04-10 17:06:43 +02:00
|
|
|
state.attachedMedias = []
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
[MUTATION_TYPES.REMOVE_MEDIA]: (state, media: Entity.Attachment) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
state.attachedMedias = state.attachedMedias.filter(m => m.id !== media.id)
|
|
|
|
},
|
2019-05-13 17:25:09 +02:00
|
|
|
[MUTATION_TYPES.UPDATE_MEDIA_DESCRIPTION]: (state, value: MediaDescription) => {
|
|
|
|
state.mediaDescriptions[value.id] = value.description
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CLEAR_MEDIA_DESCRIPTIONS]: state => {
|
|
|
|
state.mediaDescriptions = {}
|
|
|
|
},
|
2019-05-27 15:56:54 +02:00
|
|
|
[MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION]: (state, id: string) => {
|
2019-05-13 17:25:09 +02:00
|
|
|
const descriptions = state.mediaDescriptions
|
|
|
|
delete descriptions[id]
|
|
|
|
state.mediaDescriptions = descriptions
|
|
|
|
},
|
2019-04-10 17:06:43 +02:00
|
|
|
/**
|
|
|
|
* changeVisibilityValue
|
|
|
|
* Update visibility using direct value
|
|
|
|
* @param state vuex state object
|
|
|
|
* @param value visibility value
|
|
|
|
*/
|
|
|
|
[MUTATION_TYPES.CHANGE_VISIBILITY_VALUE]: (state, value: number) => {
|
|
|
|
state.visibility = value
|
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CHANGE_SENSITIVE]: (state, value: boolean) => {
|
|
|
|
state.sensitive = value
|
|
|
|
},
|
2019-05-27 15:56:54 +02:00
|
|
|
[MUTATION_TYPES.UPDATE_MEDIA_COUNT]: (state, count: number) => {
|
|
|
|
state.attachedMediaCount = count
|
2019-04-10 17:06:43 +02:00
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CHANGE_PINED_HASHTAG]: (state, value: boolean) => {
|
|
|
|
state.pinedHashtag = value
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
[MUTATION_TYPES.UPDATE_HASHTAGS]: (state, tags: Array<Entity.Tag>) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
state.hashtags = tags
|
2019-05-07 16:22:01 +02:00
|
|
|
},
|
|
|
|
[MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => {
|
|
|
|
state.loading = value
|
2019-04-10 17:06:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions: ActionTree<NewTootState, RootState> = {
|
2019-06-27 16:14:31 +02:00
|
|
|
setupLoading: ({ dispatch }) => {
|
2019-05-07 16:22:01 +02:00
|
|
|
const axiosLoading = new AxiosLoading()
|
|
|
|
axiosLoading.on('start', (_: number) => {
|
2019-06-27 16:14:31 +02:00
|
|
|
dispatch('startLoading')
|
2019-05-07 16:22:01 +02:00
|
|
|
})
|
|
|
|
axiosLoading.on('done', () => {
|
2019-06-27 16:14:31 +02:00
|
|
|
dispatch('stopLoading')
|
2019-05-07 16:22:01 +02:00
|
|
|
})
|
|
|
|
},
|
2019-06-27 16:14:31 +02:00
|
|
|
startLoading: ({ commit, state }) => {
|
|
|
|
if (state.modalOpen && !state.loading) {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stopLoading: ({ commit, state }) => {
|
|
|
|
if (state.modalOpen && state.loading) {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
|
|
|
}
|
|
|
|
},
|
2019-05-13 17:25:09 +02:00
|
|
|
updateMedia: async ({ rootState }, mediaDescription: MediaDescription) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
|
|
|
throw new AuthenticationError()
|
|
|
|
}
|
2020-03-15 09:47:56 +01:00
|
|
|
const client = generator(
|
|
|
|
rootState.TimelineSpace.sns,
|
|
|
|
rootState.TimelineSpace.account.baseURL,
|
2019-10-27 06:41:03 +01:00
|
|
|
rootState.TimelineSpace.account.accessToken,
|
|
|
|
rootState.App.userAgent,
|
|
|
|
rootState.App.proxyConfiguration
|
|
|
|
)
|
2019-05-13 17:25:09 +02:00
|
|
|
const attachments = Object.keys(mediaDescription).map(async id => {
|
|
|
|
if (mediaDescription[id] !== null) {
|
2020-03-15 09:47:56 +01:00
|
|
|
return client.updateMedia(id, { description: mediaDescription[id] })
|
2019-05-13 17:25:09 +02:00
|
|
|
} else {
|
|
|
|
return Promise.resolve({})
|
|
|
|
}
|
2019-04-10 17:24:34 +02:00
|
|
|
})
|
2019-05-07 16:22:01 +02:00
|
|
|
return Promise.all(attachments).catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
throw err
|
|
|
|
})
|
2019-04-10 17:06:43 +02:00
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
postToot: async ({ state, commit, rootState, dispatch }, params: TootForm): Promise<Entity.Status> => {
|
2019-05-13 17:25:09 +02:00
|
|
|
if (!state.modalOpen) {
|
|
|
|
throw new NewTootModalOpen()
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:56:00 +02:00
|
|
|
if (params.status.length < 1 || params.status.length > rootState.TimelineSpace.tootMax) {
|
2019-05-13 17:25:09 +02:00
|
|
|
throw new NewTootTootLength()
|
|
|
|
}
|
|
|
|
|
|
|
|
const visibilityKey: string | undefined = Object.keys(Visibility).find(key => {
|
|
|
|
return Visibility[key].value === state.visibility
|
|
|
|
})
|
2020-03-15 09:47:56 +01:00
|
|
|
let specifiedVisibility: 'public' | 'unlisted' | 'private' | 'direct' = Visibility.Public.key
|
2019-05-13 17:25:09 +02:00
|
|
|
if (visibilityKey !== undefined) {
|
|
|
|
specifiedVisibility = Visibility[visibilityKey].key
|
|
|
|
}
|
2019-07-16 16:56:00 +02:00
|
|
|
|
2019-05-13 17:25:09 +02:00
|
|
|
let form = {
|
|
|
|
visibility: specifiedVisibility,
|
|
|
|
sensitive: state.sensitive,
|
2019-07-20 15:21:40 +02:00
|
|
|
spoiler_text: params.spoiler
|
2019-05-13 17:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.replyToMessage !== null) {
|
|
|
|
form = Object.assign(form, {
|
|
|
|
in_reply_to_id: state.replyToMessage.id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:21:40 +02:00
|
|
|
if (params.polls.length > 1) {
|
|
|
|
params.polls.map(poll => {
|
|
|
|
if (poll.length < 1) {
|
|
|
|
throw new NewTootPollInvalid()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
form = Object.assign(form, {
|
|
|
|
poll: {
|
|
|
|
expires_in: params.pollExpireSeconds,
|
|
|
|
multiple: false,
|
|
|
|
options: params.polls
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-10 17:06:43 +02:00
|
|
|
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
|
|
|
throw new AuthenticationError()
|
|
|
|
}
|
|
|
|
if (state.blockSubmit) {
|
2019-05-14 16:33:28 +02:00
|
|
|
throw new NewTootBlockSubmit()
|
2019-04-10 17:06:43 +02:00
|
|
|
}
|
2019-05-13 17:25:09 +02:00
|
|
|
|
|
|
|
if (state.attachedMedias.length > 0) {
|
|
|
|
if (state.attachedMedias.length > 4) {
|
|
|
|
throw new NewTootAttachLength()
|
|
|
|
}
|
|
|
|
form = Object.assign(form, {
|
|
|
|
media_ids: state.attachedMedias.map(m => {
|
|
|
|
return m.id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Update media descriptions
|
|
|
|
await dispatch('updateMedia', state.mediaDescriptions).catch(_ => {
|
|
|
|
throw new NewTootMediaDescription()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-14 16:33:28 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true)
|
2020-03-15 09:47:56 +01:00
|
|
|
const client = generator(
|
|
|
|
rootState.TimelineSpace.sns,
|
|
|
|
rootState.TimelineSpace.account.baseURL,
|
2019-10-27 06:41:03 +01:00
|
|
|
rootState.TimelineSpace.account.accessToken,
|
|
|
|
rootState.App.userAgent,
|
|
|
|
rootState.App.proxyConfiguration
|
|
|
|
)
|
2019-05-07 16:22:01 +02:00
|
|
|
return client
|
2020-03-15 09:47:56 +01:00
|
|
|
.postStatus(params.status, form)
|
|
|
|
.then(res => {
|
2019-12-04 14:56:38 +01:00
|
|
|
win.ipcRenderer.send('toot-action-sound')
|
2019-04-10 17:06:43 +02:00
|
|
|
return res.data
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false)
|
|
|
|
})
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
openReply: ({ commit, rootState }, message: Entity.Status) => {
|
2019-04-10 17:06:43 +02:00
|
|
|
commit(MUTATION_TYPES.SET_REPLY_TO, message)
|
2019-05-07 16:22:01 +02:00
|
|
|
const mentionAccounts = [message.account.acct]
|
|
|
|
.concat(message.mentions.map(a => a.acct))
|
2019-04-10 17:06:43 +02:00
|
|
|
.filter((a, i, self) => self.indexOf(a) === i)
|
2019-05-07 16:22:01 +02:00
|
|
|
.filter(a => a !== rootState.TimelineSpace.account.username)
|
2019-04-10 17:06:43 +02:00
|
|
|
commit(MUTATION_TYPES.UPDATE_INITIAL_STATUS, `${mentionAccounts.map(m => `@${m}`).join(' ')} `)
|
|
|
|
commit(MUTATION_TYPES.UPDATE_INITIAL_SPOILER, message.spoiler_text)
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MODAL, true)
|
|
|
|
let value: number = Visibility.Public.value
|
|
|
|
Object.keys(Visibility).map(key => {
|
|
|
|
const target = Visibility[key]
|
|
|
|
if (target.key === message.visibility) {
|
|
|
|
value = target.value
|
|
|
|
}
|
|
|
|
})
|
|
|
|
commit(MUTATION_TYPES.CHANGE_VISIBILITY_VALUE, value)
|
|
|
|
},
|
|
|
|
openModal: ({ dispatch, commit, state }) => {
|
|
|
|
if (!state.replyToMessage && state.pinedHashtag) {
|
2019-05-08 15:41:17 +02:00
|
|
|
commit(MUTATION_TYPES.UPDATE_INITIAL_STATUS, state.hashtags.map(t => `#${t.name}`).join(' '))
|
2019-04-10 17:06:43 +02:00
|
|
|
}
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MODAL, true)
|
|
|
|
dispatch('fetchVisibility')
|
|
|
|
},
|
|
|
|
closeModal: ({ commit }) => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MODAL, false)
|
|
|
|
commit(MUTATION_TYPES.UPDATE_INITIAL_STATUS, '')
|
|
|
|
commit(MUTATION_TYPES.UPDATE_INITIAL_SPOILER, '')
|
|
|
|
commit(MUTATION_TYPES.SET_REPLY_TO, null)
|
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false)
|
|
|
|
commit(MUTATION_TYPES.CLEAR_ATTACHED_MEDIAS)
|
2019-05-13 17:25:09 +02:00
|
|
|
commit(MUTATION_TYPES.CLEAR_MEDIA_DESCRIPTIONS)
|
2019-04-10 17:06:43 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_SENSITIVE, false)
|
|
|
|
commit(MUTATION_TYPES.CHANGE_VISIBILITY_VALUE, Visibility.Public.value)
|
|
|
|
},
|
|
|
|
uploadImage: async ({ commit, rootState }, image: any) => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true)
|
|
|
|
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
|
|
|
throw new AuthenticationError()
|
|
|
|
}
|
2020-03-15 09:47:56 +01:00
|
|
|
const client = generator(
|
|
|
|
rootState.TimelineSpace.sns,
|
|
|
|
rootState.TimelineSpace.account.baseURL,
|
2019-10-27 06:41:03 +01:00
|
|
|
rootState.TimelineSpace.account.accessToken,
|
|
|
|
rootState.App.userAgent,
|
|
|
|
rootState.App.proxyConfiguration
|
|
|
|
)
|
2019-05-07 16:22:01 +02:00
|
|
|
return client
|
2020-03-15 09:47:56 +01:00
|
|
|
.uploadMedia(image)
|
2019-04-10 17:06:43 +02:00
|
|
|
.then(res => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false)
|
2019-05-14 16:33:28 +02:00
|
|
|
if (res.data.type === 'unknown') throw new NewTootUnknownType()
|
2019-04-10 17:06:43 +02:00
|
|
|
commit(MUTATION_TYPES.APPEND_ATTACHED_MEDIAS, res.data)
|
|
|
|
return res.data
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false)
|
|
|
|
console.error(err)
|
|
|
|
throw err
|
|
|
|
})
|
|
|
|
},
|
2019-05-27 15:56:54 +02:00
|
|
|
incrementMediaCount: ({ commit, state }) => {
|
|
|
|
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount + 1)
|
2019-04-10 17:06:43 +02:00
|
|
|
},
|
2019-05-27 15:56:54 +02:00
|
|
|
decrementMediaCount: ({ commit, state }) => {
|
|
|
|
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount - 1)
|
2019-05-13 17:25:09 +02:00
|
|
|
},
|
2019-05-27 15:56:54 +02:00
|
|
|
resetMediaCount: ({ commit }) => {
|
|
|
|
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, 0)
|
2019-04-10 17:06:43 +02:00
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
removeMedia: ({ commit, dispatch }, media: Entity.Attachment) => {
|
2019-05-13 17:25:09 +02:00
|
|
|
commit(MUTATION_TYPES.REMOVE_MEDIA, media)
|
|
|
|
commit(MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION, media.id)
|
2019-05-27 15:56:54 +02:00
|
|
|
dispatch('decrementMediaCount')
|
2019-05-13 17:25:09 +02:00
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
updateHashtags: ({ commit, state }, tags: Array<Entity.Tag>) => {
|
2019-05-12 14:44:34 +02:00
|
|
|
if (state.pinedHashtag && tags.length > 0) {
|
2019-04-10 17:06:43 +02:00
|
|
|
commit(MUTATION_TYPES.UPDATE_HASHTAGS, tags)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fetchVisibility: async ({ commit, rootState }) => {
|
2020-03-15 09:47:56 +01:00
|
|
|
const client = generator(
|
|
|
|
rootState.TimelineSpace.sns,
|
|
|
|
rootState.TimelineSpace.account.baseURL,
|
|
|
|
rootState.TimelineSpace.account.accessToken,
|
2019-10-27 06:41:03 +01:00
|
|
|
rootState.App.userAgent,
|
|
|
|
rootState.App.proxyConfiguration
|
|
|
|
)
|
2020-03-15 09:47:56 +01:00
|
|
|
const res = await client.verifyAccountCredentials()
|
2019-05-07 16:22:01 +02:00
|
|
|
const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array<VisibilityType>).find(v => {
|
2019-04-10 17:06:43 +02:00
|
|
|
return v.key === res.data.source!.privacy
|
|
|
|
})
|
|
|
|
if (visibility === undefined) {
|
|
|
|
throw new Error('Visibility value is invalid')
|
|
|
|
}
|
|
|
|
commit(MUTATION_TYPES.CHANGE_VISIBILITY_VALUE, visibility.value)
|
|
|
|
return res.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getters: GetterTree<NewTootState, RootState> = {
|
2019-05-07 16:22:01 +02:00
|
|
|
hashtagInserting: state => {
|
2019-04-10 17:06:43 +02:00
|
|
|
return !state.replyToMessage && state.pinedHashtag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const NewToot: Module<NewTootState, RootState> = {
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
Status: TootStatus
|
|
|
|
},
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
getters: getters,
|
|
|
|
actions: actions
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NewToot
|