1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-03 10:47:34 +01:00

Merge pull request #970 from h3poteto/iss-969

closes #969 Attach only polls if it is specified
This commit is contained in:
AkiraFukushima 2019-07-20 22:27:33 +09:00 committed by GitHub
commit 034e54ee6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 60 additions and 10 deletions

View File

@ -92,5 +92,10 @@
"follow_request_accept_error": "Failed to accept the request", "follow_request_accept_error": "Failed to accept the request",
"follow_reuqest_reject_error": "failed to reject the request", "follow_reuqest_reject_error": "failed to reject the request",
"start_all_streamings_error": "Failed to start streaming of {{domain}}" "start_all_streamings_error": "Failed to start streaming of {{domain}}"
},
"validation": {
"new_toot": {
"poll_invalid": "Invalid poll choices"
}
} }
} }

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

@ -59,5 +59,10 @@
"follow_request_accept_error": "Failed to accept the request", "follow_request_accept_error": "Failed to accept the request",
"follow_reuqest_reject_error": "failed to reject the request", "follow_reuqest_reject_error": "failed to reject the request",
"start_all_streamings_error": "Failed to start streaming of {{domain}}" "start_all_streamings_error": "Failed to start streaming of {{domain}}"
},
"validation": {
"new_toot": {
"poll_invalid": "Invalid poll choices"
}
} }
} }

View File

@ -48,5 +48,10 @@
"follow_request_accept_error": "Failed to accept the request", "follow_request_accept_error": "Failed to accept the request",
"follow_reuqest_reject_error": "failed to reject the request", "follow_reuqest_reject_error": "failed to reject the request",
"start_all_streamings_error": "Failed to start streaming of {{domain}}" "start_all_streamings_error": "Failed to start streaming of {{domain}}"
},
"validation": {
"new_toot": {
"poll_invalid": "Invalid poll choices"
}
} }
} }

View File

@ -406,7 +406,8 @@
"new_toot": { "new_toot": {
"toot_length": "トゥートの長さは {{min}} から {{max}}文字である必要があります", "toot_length": "トゥートの長さは {{min}} から {{max}}文字である必要があります",
"attach_length": "添付ファイルは {{max}} つまでです", "attach_length": "添付ファイルは {{max}} つまでです",
"attach_image": "画像かビデオしか添付できません" "attach_image": "画像かビデオしか添付できません",
"poll_invalid": "アンケートに不正な選択肢が含まれています"
} }
} }
} }

View File

@ -68,5 +68,10 @@
"follow_request_accept_error": "Failed to accept the request", "follow_request_accept_error": "Failed to accept the request",
"follow_reuqest_reject_error": "failed to reject the request", "follow_reuqest_reject_error": "failed to reject the request",
"start_all_streamings_error": "Failed to start streaming of {{domain}}" "start_all_streamings_error": "Failed to start streaming of {{domain}}"
},
"validation": {
"new_toot": {
"poll_invalid": "Invalid poll choices"
}
} }
} }

View File

@ -92,5 +92,10 @@
"follow_request_accept_error": "Failed to accept the request", "follow_request_accept_error": "Failed to accept the request",
"follow_reuqest_reject_error": "failed to reject the request", "follow_reuqest_reject_error": "failed to reject the request",
"start_all_streamings_error": "Failed to start streaming of {{domain}}" "start_all_streamings_error": "Failed to start streaming of {{domain}}"
},
"validation": {
"new_toot": {
"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',
@ -149,7 +149,7 @@ export default {
showContentWarning: false, showContentWarning: false,
visibilityList: Visibility, visibilityList: Visibility,
openPoll: false, openPoll: false,
polls: ['', ''], polls: [],
pollExpire: { pollExpire: {
label: this.$t('modals.new_toot.poll.expires.1_day'), label: this.$t('modals.new_toot.poll.expires.1_day'),
value: 3600 * 24 value: 3600 * 24
@ -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 {
@ -354,6 +359,11 @@ export default {
}, },
togglePollForm() { togglePollForm() {
this.openPoll = !this.openPoll this.openPoll = !this.openPoll
if (this.openPoll) {
this.polls = ['', '']
} else {
this.polls = []
}
}, },
addPoll() { addPoll() {
this.polls.push('') this.polls.push('')

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()
} }