refs #969 Attach poll only specified, and block invalid poll options

This commit is contained in:
AkiraFukushima 2019-07-20 22:21:40 +09:00
parent aeed12cd59
commit d44651e9e9
4 changed files with 27 additions and 8 deletions

View File

@ -406,7 +406,8 @@
"new_toot": { "new_toot": {
"toot_length": "Toot length should be {{min}} to {{max}}", "toot_length": "Toot length should be {{min}} to {{max}}",
"attach_length": "You can only attach up to {{max}} images", "attach_length": "You can only attach up to {{max}} images",
"attach_image": "You can only attach images or videos" "attach_image": "You can only attach images or videos",
"poll_invalid": "Invalid poll choices"
} }
} }
} }

View File

@ -134,7 +134,7 @@ import { clipboard } from 'electron'
import Visibility from '~/src/constants/visibility' import Visibility from '~/src/constants/visibility'
import Status from './NewToot/Status' import Status from './NewToot/Status'
import Poll from './NewToot/Poll' import Poll from './NewToot/Poll'
import { NewTootTootLength, NewTootAttachLength, NewTootModalOpen, NewTootBlockSubmit } from '@/errors/validations' import { NewTootTootLength, NewTootAttachLength, NewTootModalOpen, NewTootBlockSubmit, NewTootPollInvalid } from '@/errors/validations'
export default { export default {
name: 'new-toot', name: 'new-toot',
@ -261,6 +261,11 @@ export default {
message: this.$t('validation.new_toot.attach_length', { max: 4 }), message: this.$t('validation.new_toot.attach_length', { max: 4 }),
type: 'error' type: 'error'
}) })
} else if (err instanceof NewTootPollInvalid) {
this.$message({
message: this.$t('validation.new_toot.poll_invalid'),
type: 'error'
})
} else if (err instanceof NewTootModalOpen || err instanceof NewTootBlockSubmit) { } else if (err instanceof NewTootModalOpen || err instanceof NewTootBlockSubmit) {
// Nothing // Nothing
} else { } else {

View File

@ -8,6 +8,8 @@ export class NewTootAttachLength extends Error {}
export class NewTootMediaDescription extends Error {} export class NewTootMediaDescription extends Error {}
export class NewTootPollInvalid extends Error {}
export class NewTootUnknownType extends Error {} export class NewTootUnknownType extends Error {}
export class AuthenticationError extends Error {} export class AuthenticationError extends Error {}

View File

@ -11,6 +11,7 @@ import {
NewTootTootLength, NewTootTootLength,
NewTootAttachLength, NewTootAttachLength,
NewTootMediaDescription, NewTootMediaDescription,
NewTootPollInvalid,
NewTootUnknownType, NewTootUnknownType,
AuthenticationError AuthenticationError
} from '@/errors/validations' } from '@/errors/validations'
@ -205,12 +206,7 @@ const actions: ActionTree<NewTootState, RootState> = {
status: params.status, status: params.status,
visibility: specifiedVisibility, visibility: specifiedVisibility,
sensitive: state.sensitive, sensitive: state.sensitive,
spoiler_text: params.spoiler, spoiler_text: params.spoiler
poll: {
expires_in: params.pollExpireSeconds,
multiple: false,
options: params.polls
}
} }
if (state.replyToMessage !== null) { if (state.replyToMessage !== null) {
@ -219,6 +215,21 @@ const actions: ActionTree<NewTootState, RootState> = {
}) })
} }
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
}
})
}
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) { if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
throw new AuthenticationError() throw new AuthenticationError()
} }