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": {
"toot_length": "Toot length should be {{min}} to {{max}}",
"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 Status from './NewToot/Status'
import Poll from './NewToot/Poll'
import { NewTootTootLength, NewTootAttachLength, NewTootModalOpen, NewTootBlockSubmit } from '@/errors/validations'
import { NewTootTootLength, NewTootAttachLength, NewTootModalOpen, NewTootBlockSubmit, NewTootPollInvalid } from '@/errors/validations'
export default {
name: 'new-toot',
@ -261,6 +261,11 @@ export default {
message: this.$t('validation.new_toot.attach_length', { max: 4 }),
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) {
// Nothing
} else {

View File

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

View File

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