From 4407f07014096bcbaf5a06015a5791984282846d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 03:57:46 +0100 Subject: [PATCH 1/9] Render unicode emoji in polls using emoji pack (#10185) --- app/javascript/mastodon/actions/importer/index.js | 4 ++-- .../mastodon/actions/importer/normalizer.js | 11 +++++++++++ app/javascript/mastodon/components/poll.js | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/actions/importer/index.js b/app/javascript/mastodon/actions/importer/index.js index abadee8173f..e990dc04cb6 100644 --- a/app/javascript/mastodon/actions/importer/index.js +++ b/app/javascript/mastodon/actions/importer/index.js @@ -1,4 +1,4 @@ -import { normalizeAccount, normalizeStatus } from './normalizer'; +import { normalizeAccount, normalizeStatus, normalizePoll } from './normalizer'; export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT'; export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT'; @@ -71,7 +71,7 @@ export function importFetchedStatuses(statuses) { } if (status.poll && status.poll.id) { - pushUnique(polls, status.poll); + pushUnique(polls, normalizePoll(status.poll)); } } diff --git a/app/javascript/mastodon/actions/importer/normalizer.js b/app/javascript/mastodon/actions/importer/normalizer.js index 3085cd53779..ea80c0efb39 100644 --- a/app/javascript/mastodon/actions/importer/normalizer.js +++ b/app/javascript/mastodon/actions/importer/normalizer.js @@ -67,3 +67,14 @@ export function normalizeStatus(status, normalOldStatus) { return normalStatus; } + +export function normalizePoll(poll) { + const normalPoll = { ...poll }; + + normalPoll.options = poll.options.map(option => ({ + ...option, + title_emojified: emojify(escapeTextContentForBrowser(option.title)), + })); + + return normalPoll; +} diff --git a/app/javascript/mastodon/components/poll.js b/app/javascript/mastodon/components/poll.js index 182491af865..c52445c86f0 100644 --- a/app/javascript/mastodon/components/poll.js +++ b/app/javascript/mastodon/components/poll.js @@ -120,7 +120,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - {option.get('title')} + ); From d97cbb0da60f32c9e7e60445af329173b0df1aa7 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 04:53:37 +0100 Subject: [PATCH 2/9] Add UI for creating polls (#10184) * Add actions and reducers for polls * Add poll button * Disable media upload if poll enabled * Add poll form * Make delete & redraft work with polls --- app/javascript/mastodon/actions/compose.js | 52 +++++++- app/javascript/mastodon/actions/statuses.js | 6 +- .../compose/components/compose_form.js | 4 + .../compose/components/poll_button.js | 55 ++++++++ .../features/compose/components/poll_form.js | 121 ++++++++++++++++++ .../compose/components/upload_button.js | 6 +- .../containers/poll_button_container.js | 24 ++++ .../compose/containers/poll_form_container.js | 29 +++++ .../containers/upload_button_container.js | 1 + app/javascript/mastodon/reducers/compose.js | 35 +++++ app/javascript/styles/mastodon/polls.scss | 88 +++++++++++++ 11 files changed, 418 insertions(+), 3 deletions(-) create mode 100644 app/javascript/mastodon/features/compose/components/poll_button.js create mode 100644 app/javascript/mastodon/features/compose/components/poll_form.js create mode 100644 app/javascript/mastodon/features/compose/containers/poll_button_container.js create mode 100644 app/javascript/mastodon/features/compose/containers/poll_form_container.js diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 0be2a5cd467..2d58a71febd 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -51,6 +51,13 @@ export const COMPOSE_UPLOAD_CHANGE_REQUEST = 'COMPOSE_UPLOAD_UPDATE_REQUEST' export const COMPOSE_UPLOAD_CHANGE_SUCCESS = 'COMPOSE_UPLOAD_UPDATE_SUCCESS'; export const COMPOSE_UPLOAD_CHANGE_FAIL = 'COMPOSE_UPLOAD_UPDATE_FAIL'; +export const COMPOSE_POLL_ADD = 'COMPOSE_POLL_ADD'; +export const COMPOSE_POLL_REMOVE = 'COMPOSE_POLL_REMOVE'; +export const COMPOSE_POLL_OPTION_ADD = 'COMPOSE_POLL_OPTION_ADD'; +export const COMPOSE_POLL_OPTION_CHANGE = 'COMPOSE_POLL_OPTION_CHANGE'; +export const COMPOSE_POLL_OPTION_REMOVE = 'COMPOSE_POLL_OPTION_REMOVE'; +export const COMPOSE_POLL_SETTINGS_CHANGE = 'COMPOSE_POLL_SETTINGS_CHANGE'; + const messages = defineMessages({ uploadErrorLimit: { id: 'upload_error.limit', defaultMessage: 'File upload limit exceeded.' }, }); @@ -131,6 +138,7 @@ export function submitCompose(routerHistory) { sensitive: getState().getIn(['compose', 'sensitive']), spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''), visibility: getState().getIn(['compose', 'privacy']), + poll: getState().getIn(['compose', 'poll'], null), }, { headers: { 'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']), @@ -484,4 +492,46 @@ export function changeComposing(value) { type: COMPOSE_COMPOSING_CHANGE, value, }; -} +}; + +export function addPoll() { + return { + type: COMPOSE_POLL_ADD, + }; +}; + +export function removePoll() { + return { + type: COMPOSE_POLL_REMOVE, + }; +}; + +export function addPollOption(title) { + return { + type: COMPOSE_POLL_OPTION_ADD, + title, + }; +}; + +export function changePollOption(index, title) { + return { + type: COMPOSE_POLL_OPTION_CHANGE, + index, + title, + }; +}; + +export function removePollOption(index) { + return { + type: COMPOSE_POLL_OPTION_REMOVE, + index, + }; +}; + +export function changePollSettings(expiresIn, isMultiple) { + return { + type: COMPOSE_POLL_SETTINGS_CHANGE, + expiresIn, + isMultiple, + }; +}; diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index e7c89b4ba8a..1794538e2b5 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -140,7 +140,11 @@ export function redraft(status) { export function deleteStatus(id, router, withRedraft = false) { return (dispatch, getState) => { - const status = getState().getIn(['statuses', id]); + let status = getState().getIn(['statuses', id]); + + if (status.get('poll')) { + status = status.set('poll', getState().getIn(['polls', status.get('poll')])); + } dispatch(deleteStatusRequest(id)); diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index a990e749817..4b0bde65983 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -5,12 +5,14 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import ReplyIndicatorContainer from '../containers/reply_indicator_container'; import AutosuggestTextarea from '../../../components/autosuggest_textarea'; +import PollButtonContainer from '../containers/poll_button_container'; import UploadButtonContainer from '../containers/upload_button_container'; import { defineMessages, injectIntl } from 'react-intl'; import SpoilerButtonContainer from '../containers/spoiler_button_container'; import PrivacyDropdownContainer from '../containers/privacy_dropdown_container'; import SensitiveButtonContainer from '../containers/sensitive_button_container'; import EmojiPickerDropdown from '../containers/emoji_picker_dropdown_container'; +import PollFormContainer from '../containers/poll_form_container'; import UploadFormContainer from '../containers/upload_form_container'; import WarningContainer from '../containers/warning_container'; import { isMobile } from '../../../is_mobile'; @@ -205,11 +207,13 @@ class ComposeForm extends ImmutablePureComponent {
+
+ diff --git a/app/javascript/mastodon/features/compose/components/poll_button.js b/app/javascript/mastodon/features/compose/components/poll_button.js new file mode 100644 index 00000000000..76f96bfa41e --- /dev/null +++ b/app/javascript/mastodon/features/compose/components/poll_button.js @@ -0,0 +1,55 @@ +import React from 'react'; +import IconButton from '../../../components/icon_button'; +import PropTypes from 'prop-types'; +import { defineMessages, injectIntl } from 'react-intl'; + +const messages = defineMessages({ + add_poll: { id: 'poll_button.add_poll', defaultMessage: 'Add a poll' }, + remove_poll: { id: 'poll_button.remove_poll', defaultMessage: 'Remove poll' }, +}); + +const iconStyle = { + height: null, + lineHeight: '27px', +}; + +export default +@injectIntl +class PollButton extends React.PureComponent { + + static propTypes = { + disabled: PropTypes.bool, + unavailable: PropTypes.bool, + active: PropTypes.bool, + onClick: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + handleClick = () => { + this.props.onClick(); + } + + render () { + const { intl, active, unavailable, disabled } = this.props; + + if (unavailable) { + return null; + } + + return ( +
+ +
+ ); + } + +} diff --git a/app/javascript/mastodon/features/compose/components/poll_form.js b/app/javascript/mastodon/features/compose/components/poll_form.js new file mode 100644 index 00000000000..ff0062425da --- /dev/null +++ b/app/javascript/mastodon/features/compose/components/poll_form.js @@ -0,0 +1,121 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; +import IconButton from 'mastodon/components/icon_button'; +import Icon from 'mastodon/components/icon'; +import classNames from 'classnames'; + +const messages = defineMessages({ + option_placeholder: { id: 'compose_form.poll.option_placeholder', defaultMessage: 'Choice {number}' }, + add_option: { id: 'compose_form.poll.add_option', defaultMessage: 'Add a choice' }, + remove_option: { id: 'compose_form.poll.remove_option', defaultMessage: 'Remove this choice' }, + poll_duration: { id: 'compose_form.poll.duration', defaultMessage: 'Poll duration' }, + minutes: { id: 'intervals.full.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}}' }, + hours: { id: 'intervals.full.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}}' }, + days: { id: 'intervals.full.days', defaultMessage: '{number, plural, one {# day} other {# days}}' }, +}); + +@injectIntl +class Option extends React.PureComponent { + + static propTypes = { + title: PropTypes.string.isRequired, + index: PropTypes.number.isRequired, + isPollMultiple: PropTypes.bool, + onChange: PropTypes.func.isRequired, + onRemove: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + handleOptionTitleChange = e => { + this.props.onChange(this.props.index, e.target.value); + }; + + handleOptionRemove = () => { + this.props.onRemove(this.props.index); + }; + + render () { + const { isPollMultiple, title, index, intl } = this.props; + + return ( +
  • + + +
    + +
    +
  • + ); + } + +} + +export default +@injectIntl +class PollForm extends ImmutablePureComponent { + + static propTypes = { + options: ImmutablePropTypes.list, + expiresIn: PropTypes.number, + isMultiple: PropTypes.bool, + onChangeOption: PropTypes.func.isRequired, + onAddOption: PropTypes.func.isRequired, + onRemoveOption: PropTypes.func.isRequired, + onChangeSettings: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + handleAddOption = () => { + this.props.onAddOption(''); + }; + + handleSelectDuration = e => { + this.props.onChangeSettings(e.target.value, this.props.isMultiple); + }; + + render () { + const { options, expiresIn, isMultiple, onChangeOption, onRemoveOption, intl } = this.props; + + if (!options) { + return null; + } + + return ( +
    +
      + {options.map((title, i) =>
    + +
    + {options.size < 4 && ( + + )} + + +
    +
    + ); + } + +} diff --git a/app/javascript/mastodon/features/compose/components/upload_button.js b/app/javascript/mastodon/features/compose/components/upload_button.js index db55ad70bf7..90e2769f3be 100644 --- a/app/javascript/mastodon/features/compose/components/upload_button.js +++ b/app/javascript/mastodon/features/compose/components/upload_button.js @@ -29,6 +29,7 @@ class UploadButton extends ImmutablePureComponent { static propTypes = { disabled: PropTypes.bool, + unavailable: PropTypes.bool, onSelectFile: PropTypes.func.isRequired, style: PropTypes.object, resetFileKey: PropTypes.number, @@ -51,8 +52,11 @@ class UploadButton extends ImmutablePureComponent { } render () { + const { intl, resetFileKey, unavailable, disabled, acceptContentTypes } = this.props; - const { intl, resetFileKey, disabled, acceptContentTypes } = this.props; + if (unavailable) { + return null; + } return (
    diff --git a/app/javascript/mastodon/features/compose/containers/poll_button_container.js b/app/javascript/mastodon/features/compose/containers/poll_button_container.js new file mode 100644 index 00000000000..8f1cb7c10a5 --- /dev/null +++ b/app/javascript/mastodon/features/compose/containers/poll_button_container.js @@ -0,0 +1,24 @@ +import { connect } from 'react-redux'; +import PollButton from '../components/poll_button'; +import { addPoll, removePoll } from '../../../actions/compose'; + +const mapStateToProps = state => ({ + unavailable: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size > 0), + active: state.getIn(['compose', 'poll']) !== null, +}); + +const mapDispatchToProps = dispatch => ({ + + onClick () { + dispatch((_, getState) => { + if (getState().getIn(['compose', 'poll'])) { + dispatch(removePoll()); + } else { + dispatch(addPoll()); + } + }); + }, + +}); + +export default connect(mapStateToProps, mapDispatchToProps)(PollButton); diff --git a/app/javascript/mastodon/features/compose/containers/poll_form_container.js b/app/javascript/mastodon/features/compose/containers/poll_form_container.js new file mode 100644 index 00000000000..da795a29121 --- /dev/null +++ b/app/javascript/mastodon/features/compose/containers/poll_form_container.js @@ -0,0 +1,29 @@ +import { connect } from 'react-redux'; +import PollForm from '../components/poll_form'; +import { addPollOption, removePollOption, changePollOption, changePollSettings } from '../../../actions/compose'; + +const mapStateToProps = state => ({ + options: state.getIn(['compose', 'poll', 'options']), + expiresIn: state.getIn(['compose', 'poll', 'expires_in']), + isMultiple: state.getIn(['compose', 'poll', 'multiple']), +}); + +const mapDispatchToProps = dispatch => ({ + onAddOption(title) { + dispatch(addPollOption(title)); + }, + + onRemoveOption(index) { + dispatch(removePollOption(index)); + }, + + onChangeOption(index, title) { + dispatch(changePollOption(index, title)); + }, + + onChangeSettings(expiresIn, isMultiple) { + dispatch(changePollSettings(expiresIn, isMultiple)); + }, +}); + +export default connect(mapStateToProps, mapDispatchToProps)(PollForm); diff --git a/app/javascript/mastodon/features/compose/containers/upload_button_container.js b/app/javascript/mastodon/features/compose/containers/upload_button_container.js index 1f1d915bc84..d8b8c4b6ee7 100644 --- a/app/javascript/mastodon/features/compose/containers/upload_button_container.js +++ b/app/javascript/mastodon/features/compose/containers/upload_button_container.js @@ -4,6 +4,7 @@ import { uploadCompose } from '../../../actions/compose'; const mapStateToProps = state => ({ disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size > 3 || state.getIn(['compose', 'media_attachments']).some(m => m.get('type') === 'video')), + unavailable: state.getIn(['compose', 'poll']) !== null, resetFileKey: state.getIn(['compose', 'resetFileKey']), }); diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index 1622871b8ff..b45def281b6 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -29,6 +29,12 @@ import { COMPOSE_UPLOAD_CHANGE_SUCCESS, COMPOSE_UPLOAD_CHANGE_FAIL, COMPOSE_RESET, + COMPOSE_POLL_ADD, + COMPOSE_POLL_REMOVE, + COMPOSE_POLL_OPTION_ADD, + COMPOSE_POLL_OPTION_CHANGE, + COMPOSE_POLL_OPTION_REMOVE, + COMPOSE_POLL_SETTINGS_CHANGE, } from '../actions/compose'; import { TIMELINE_DELETE } from '../actions/timelines'; import { STORE_HYDRATE } from '../actions/store'; @@ -55,6 +61,7 @@ const initialState = ImmutableMap({ is_uploading: false, progress: 0, media_attachments: ImmutableList(), + poll: null, suggestion_token: null, suggestions: ImmutableList(), default_privacy: 'public', @@ -64,6 +71,12 @@ const initialState = ImmutableMap({ tagHistory: ImmutableList(), }); +const initialPoll = ImmutableMap({ + options: ImmutableList(['', '']), + expires_in: 24 * 3600, + multiple: false, +}); + function statusToTextMentions(state, status) { let set = ImmutableOrderedSet([]); @@ -85,6 +98,7 @@ function clearAll(state) { map.set('privacy', state.get('default_privacy')); map.set('sensitive', false); map.update('media_attachments', list => list.clear()); + map.set('poll', null); map.set('idempotencyKey', uuid()); }); }; @@ -247,6 +261,7 @@ export default function compose(state = initialState, action) { map.set('spoiler', false); map.set('spoiler_text', ''); map.set('privacy', state.get('default_privacy')); + map.set('poll', null); map.set('idempotencyKey', uuid()); }); case COMPOSE_SUBMIT_REQUEST: @@ -329,7 +344,27 @@ export default function compose(state = initialState, action) { map.set('spoiler', false); map.set('spoiler_text', ''); } + + if (action.status.get('poll')) { + map.set('poll', ImmutableMap({ + options: action.status.getIn(['poll', 'options']).map(x => x.get('title')), + multiple: action.status.getIn(['poll', 'multiple']), + expires_in: 24 * 3600, + })); + } }); + case COMPOSE_POLL_ADD: + return state.set('poll', initialPoll); + case COMPOSE_POLL_REMOVE: + return state.set('poll', null); + case COMPOSE_POLL_OPTION_ADD: + return state.updateIn(['poll', 'options'], options => options.push(action.title)); + case COMPOSE_POLL_OPTION_CHANGE: + return state.setIn(['poll', 'options', action.index], action.title); + case COMPOSE_POLL_OPTION_REMOVE: + return state.updateIn(['poll', 'options'], options => options.delete(action.index)); + case COMPOSE_POLL_SETTINGS_CHANGE: + return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple)); default: return state; } diff --git a/app/javascript/styles/mastodon/polls.scss b/app/javascript/styles/mastodon/polls.scss index 7c6e61d6301..d86cef44c58 100644 --- a/app/javascript/styles/mastodon/polls.scss +++ b/app/javascript/styles/mastodon/polls.scss @@ -33,9 +33,34 @@ display: none; } + input[type=text] { + display: block; + box-sizing: border-box; + flex: 1 1 auto; + width: 20px; + font-size: 14px; + color: $inverted-text-color; + display: block; + outline: 0; + font-family: inherit; + background: $simple-background-color; + border: 1px solid darken($simple-background-color, 14%); + border-radius: 4px; + padding: 6px 10px; + + &:focus { + border-color: $highlight-text-color; + } + } + &.selectable { cursor: pointer; } + + &.editable { + display: flex; + align-items: center; + } } &__input { @@ -45,6 +70,7 @@ box-sizing: border-box; width: 18px; height: 18px; + flex: 0 0 auto; margin-right: 10px; top: -1px; border-radius: 50%; @@ -98,3 +124,65 @@ font-size: 14px; } } + +.compose-form__poll-wrapper { + border-top: 1px solid darken($simple-background-color, 8%); + + ul { + padding: 10px; + } + + .poll__footer { + border-top: 1px solid darken($simple-background-color, 8%); + padding: 10px; + display: flex; + align-items: center; + + button, + select { + flex: 1 1 50%; + } + } + + .button.button-secondary { + font-size: 14px; + font-weight: 400; + padding: 6px 10px; + height: auto; + line-height: inherit; + color: $action-button-color; + border-color: $action-button-color; + margin-right: 5px; + } + + li { + display: flex; + align-items: center; + + .poll__text { + flex: 0 0 auto; + width: calc(100% - (23px + 6px)); + margin-right: 6px; + } + } + + select { + appearance: none; + box-sizing: border-box; + font-size: 14px; + color: $inverted-text-color; + display: inline-block; + width: auto; + outline: 0; + font-family: inherit; + background: $simple-background-color url("data:image/svg+xml;utf8,") no-repeat right 8px center / auto 16px; + border: 1px solid darken($simple-background-color, 14%); + border-radius: 4px; + padding: 6px 10px; + padding-right: 30px; + } + + .icon-button.disabled { + color: darken($simple-background-color, 14%); + } +} From 5996be994d7a27ffb5075d663acf02dddc32ea7e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 04:54:11 +0100 Subject: [PATCH 3/9] Fix poll validation issues (#10186) - Fix missing interpolation argument in PollValidator - Fix PollValidator rejecting exact allowed min/max durations --- app/validators/poll_validator.rb | 4 ++-- config/locales/co.yml | 4 ++-- config/locales/cs.yml | 4 ++-- config/locales/el.yml | 4 ++-- config/locales/en.yml | 4 ++-- config/locales/fa.yml | 4 ++-- config/locales/fr.yml | 4 ++-- config/locales/gl.yml | 4 ++-- config/locales/ko.yml | 4 ++-- config/locales/sk.yml | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/validators/poll_validator.rb b/app/validators/poll_validator.rb index d4ae4c16ab6..fd497c8d0b9 100644 --- a/app/validators/poll_validator.rb +++ b/app/validators/poll_validator.rb @@ -13,7 +13,7 @@ class PollValidator < ActiveModel::Validator poll.errors.add(:options, I18n.t('polls.errors.too_many_options', max: MAX_OPTIONS)) if poll.options.size > MAX_OPTIONS poll.errors.add(:options, I18n.t('polls.errors.over_character_limit', max: MAX_OPTION_CHARS)) if poll.options.any? { |option| option.mb_chars.grapheme_length > MAX_OPTION_CHARS } poll.errors.add(:options, I18n.t('polls.errors.duplicate_options')) unless poll.options.uniq.size == poll.options.size - poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_long')) if poll.expires_at.nil? || poll.expires_at - current_time >= MAX_EXPIRATION - poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if poll.expires_at.present? && poll.expires_at - current_time <= MIN_EXPIRATION + poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_long')) if poll.expires_at.nil? || poll.expires_at - current_time > MAX_EXPIRATION + poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if poll.expires_at.present? && poll.expires_at - current_time < MIN_EXPIRATION end end diff --git a/config/locales/co.yml b/config/locales/co.yml index d30fc9e967b..8fcb27598e5 100644 --- a/config/locales/co.yml +++ b/config/locales/co.yml @@ -741,9 +741,9 @@ co: duration_too_long: hè troppu luntanu indè u futuru duration_too_short: hè troppu prossimu expired: U scandagliu hè digià finitu - over_character_limit: ùn ponu micca esse più longhi chè %{MAX} caratteri + over_character_limit: ùn ponu micca esse più longhi chè %{max} caratteri too_few_options: deve avè più d'un'uzzione - too_many_options: ùn pò micca avè più di %{MAX} uzzione + too_many_options: ùn pò micca avè più di %{max} uzzione preferences: languages: Lingue other: Altre diff --git a/config/locales/cs.yml b/config/locales/cs.yml index e751b5266fc..fe83bd57ad7 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -752,9 +752,9 @@ cs: duration_too_long: je příliš daleko v budoucnosti duration_too_short: je příliš brzy expired: Anketa již skončila - over_character_limit: nesmí být každá delší než %{MAX} znaků + over_character_limit: nesmí být každá delší než %{max} znaků too_few_options: musí mít více než jednu položku - too_many_options: nesmí obsahovat více než %{MAX} položky + too_many_options: nesmí obsahovat více než %{max} položky preferences: languages: Jazyky other: Ostatní diff --git a/config/locales/el.yml b/config/locales/el.yml index ca821c4fc54..35da50af7c0 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -740,9 +740,9 @@ el: duration_too_long: είναι πολύ μακριά στο μέλλον duration_too_short: είναι πολύ σύντομα expired: Η ψηφοφορία έχει ήδη λήξει - over_character_limit: δε μπορεί να υπερβαίνει τους %{MAX} χαρακτήρες έκαστη + over_character_limit: δε μπορεί να υπερβαίνει τους %{max} χαρακτήρες έκαστη too_few_options: πρέπει να έχει περισσότερες από μια επιλογές - too_many_options: δεν μπορεί να έχει περισσότερες από %{MAX} επιλογές + too_many_options: δεν μπορεί να έχει περισσότερες από %{max} επιλογές preferences: languages: Γλώσσες other: Άλλο diff --git a/config/locales/en.yml b/config/locales/en.yml index 2d23b1eb6e9..f714884f971 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -741,9 +741,9 @@ en: duration_too_long: is too far into the future duration_too_short: is too soon expired: The poll has already ended - over_character_limit: cannot be longer than %{MAX} characters each + over_character_limit: cannot be longer than %{max} characters each too_few_options: must have more than one item - too_many_options: can't contain more than %{MAX} items + too_many_options: can't contain more than %{max} items preferences: languages: Languages other: Other diff --git a/config/locales/fa.yml b/config/locales/fa.yml index 4cf8f415c1f..4214e793cbe 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -741,9 +741,9 @@ fa: duration_too_long: در آیندهٔ خیلی دور است duration_too_short: در آیندهٔ خیلی نزدیک است expired: این نظرسنجی به پایان رسیده است - over_character_limit: هر کدام نمی‌تواند از %{MAX} نویسه طولانی‌تر باشد + over_character_limit: هر کدام نمی‌تواند از %{max} نویسه طولانی‌تر باشد too_few_options: حتماً باید بیش از یک گزینه داشته باشد - too_many_options: نمی‌تواند بیشتر از %{MAX} گزینه داشته باشد + too_many_options: نمی‌تواند بیشتر از %{max} گزینه داشته باشد preferences: languages: تنظیمات زبان other: سایر تنظیمات diff --git a/config/locales/fr.yml b/config/locales/fr.yml index c84dc806399..b9d813e9e57 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -741,9 +741,9 @@ fr: duration_too_long: est trop loin dans le futur duration_too_short: est trop tôt expired: Ce sondage est déjà terminé - over_character_limit: ne peuvent être plus long que %{MAX} caractères chacun + over_character_limit: ne peuvent être plus long que %{max} caractères chacun too_few_options: doit avoir plus qu'une proposition - too_many_options: ne peut contenir plus que %{MAX} propositions + too_many_options: ne peut contenir plus que %{max} propositions preferences: languages: Langues other: Autre diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 3c58e04f5ce..2435137f922 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -741,9 +741,9 @@ gl: duration_too_long: está moi lonxe no futuro duration_too_short: é demasiado cedo expired: A sondaxe rematou - over_character_limit: non poden ter máis de %{MAX} caracteres cada unha + over_character_limit: non poden ter máis de %{max} caracteres cada unha too_few_options: debe ter máis de unha opción - too_many_options: non pode haber máis de %{MAX} opcións + too_many_options: non pode haber máis de %{max} opcións preferences: languages: Idiomas other: Outro diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 6fa18b12a48..fe347a7037d 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -743,9 +743,9 @@ ko: duration_too_long: 너무 먼 미래입니다 duration_too_short: 너무 가깝습니다 expired: 투표가 이미 끝났습니다 - over_character_limit: 각각 %{MAX} 글자를 넘을 수 없습니다 + over_character_limit: 각각 %{max} 글자를 넘을 수 없습니다 too_few_options: 한가지 이상의 항목을 포함해야 합니다 - too_many_options: 항목은 %{MAX}개를 넘을 수 없습니다 + too_many_options: 항목은 %{max}개를 넘을 수 없습니다 preferences: languages: 언어 other: 기타 diff --git a/config/locales/sk.yml b/config/locales/sk.yml index b29a7a934a1..0800b8f8caa 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -752,9 +752,9 @@ sk: duration_too_long: je príliš ďaleko do budúcnosti duration_too_short: je príliš skoro expired: Anketa už skončila - over_character_limit: každá nemôže byť dlhšia ako %{MAX} znakov + over_character_limit: každá nemôže byť dlhšia ako %{max} znakov too_few_options: musí mať viac ako jednu položku - too_many_options: nemôže zahŕňať viac ako %{MAX} položiek + too_many_options: nemôže zahŕňať viac ako %{max} položiek preferences: languages: Jazyky other: Ostatné From 57643557b64bc1853c4aeb65fc652dac3467fa18 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 04:54:32 +0100 Subject: [PATCH 4/9] Avoid line breaks in poll options (#10188) --- app/javascript/styles/mastodon/polls.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/javascript/styles/mastodon/polls.scss b/app/javascript/styles/mastodon/polls.scss index d86cef44c58..4f8c94d8391 100644 --- a/app/javascript/styles/mastodon/polls.scss +++ b/app/javascript/styles/mastodon/polls.scss @@ -5,6 +5,7 @@ li { margin-bottom: 10px; position: relative; + height: 18px + 12px; } &__chart { @@ -27,6 +28,9 @@ padding: 6px 0; line-height: 18px; cursor: default; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; input[type=radio], input[type=checkbox] { From fd128b9c7aa5c71adbfc2e223212514c0baee675 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 05:35:52 +0100 Subject: [PATCH 5/9] Fix poll options not rendering text after vote/refresh (#10189) * Fix poll options not rendering text after vote/refresh * Fix poll options not showing up on public pages * Fix code style issue --- app/javascript/mastodon/actions/importer/index.js | 6 ++++++ app/javascript/mastodon/actions/polls.js | 11 +++++++++-- app/javascript/mastodon/components/poll.js | 4 +++- app/javascript/mastodon/reducers/polls.js | 4 ---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/javascript/mastodon/actions/importer/index.js b/app/javascript/mastodon/actions/importer/index.js index e990dc04cb6..f4372fb31d0 100644 --- a/app/javascript/mastodon/actions/importer/index.js +++ b/app/javascript/mastodon/actions/importer/index.js @@ -82,3 +82,9 @@ export function importFetchedStatuses(statuses) { dispatch(importStatuses(normalStatuses)); }; } + +export function importFetchedPoll(poll) { + return dispatch => { + dispatch(importPolls([normalizePoll(poll)])); + }; +} diff --git a/app/javascript/mastodon/actions/polls.js b/app/javascript/mastodon/actions/polls.js index bee4c48a692..8e8b82df5d0 100644 --- a/app/javascript/mastodon/actions/polls.js +++ b/app/javascript/mastodon/actions/polls.js @@ -1,4 +1,5 @@ import api from '../api'; +import { importFetchedPoll } from './importer'; export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS'; @@ -12,7 +13,10 @@ export const vote = (pollId, choices) => (dispatch, getState) => { dispatch(voteRequest()); api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices }) - .then(({ data }) => dispatch(voteSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(voteSuccess(data)); + }) .catch(err => dispatch(voteFail(err))); }; @@ -20,7 +24,10 @@ export const fetchPoll = pollId => (dispatch, getState) => { dispatch(fetchPollRequest()); api(getState).get(`/api/v1/polls/${pollId}`) - .then(({ data }) => dispatch(fetchPollSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(fetchPollSuccess(data)); + }) .catch(err => dispatch(fetchPollFail(err))); }; diff --git a/app/javascript/mastodon/components/poll.js b/app/javascript/mastodon/components/poll.js index c52445c86f0..bfff7b60116 100644 --- a/app/javascript/mastodon/components/poll.js +++ b/app/javascript/mastodon/components/poll.js @@ -7,6 +7,8 @@ import classNames from 'classnames'; import { vote, fetchPoll } from 'mastodon/actions/polls'; import Motion from 'mastodon/features/ui/util/optional_motion'; import spring from 'react-motion/lib/spring'; +import escapeTextContentForBrowser from 'escape-html'; +import emojify from 'mastodon/features/emoji/emoji'; const messages = defineMessages({ moments: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' }, @@ -120,7 +122,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - + ); diff --git a/app/javascript/mastodon/reducers/polls.js b/app/javascript/mastodon/reducers/polls.js index 53d9b1d8cb4..9956cf83f60 100644 --- a/app/javascript/mastodon/reducers/polls.js +++ b/app/javascript/mastodon/reducers/polls.js @@ -1,4 +1,3 @@ -import { POLL_VOTE_SUCCESS, POLL_FETCH_SUCCESS } from 'mastodon/actions/polls'; import { POLLS_IMPORT } from 'mastodon/actions/importer'; import { Map as ImmutableMap, fromJS } from 'immutable'; @@ -10,9 +9,6 @@ export default function polls(state = initialState, action) { switch(action.type) { case POLLS_IMPORT: return importPolls(state, action.polls); - case POLL_VOTE_SUCCESS: - case POLL_FETCH_SUCCESS: - return importPolls(state, [action.poll]); default: return state; } From ad6f7ea25036e7065a1a04d020e2f51023e2e614 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 6 Mar 2019 14:58:13 +0900 Subject: [PATCH 6/9] Bump active_record_query_trace from 1.5.4 to 1.6 (#10192) Bumps [active_record_query_trace](https://github.com/brunofacca/active-record-query-trace) from 1.5.4 to 1.6. - [Release notes](https://github.com/brunofacca/active-record-query-trace/releases) - [Changelog](https://github.com/brunofacca/active-record-query-trace/blob/v1.6/HISTORY.md) - [Commits](https://github.com/brunofacca/active-record-query-trace/compare/v1.5.4...v1.6) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 46d77f6626e..9f8647ff6b9 100644 --- a/Gemfile +++ b/Gemfile @@ -119,7 +119,7 @@ group :test do end group :development do - gem 'active_record_query_trace', '~> 1.5' + gem 'active_record_query_trace', '~> 1.6' gem 'annotate', '~> 2.7' gem 'better_errors', '~> 2.5' gem 'binding_of_caller', '~> 0.7' diff --git a/Gemfile.lock b/Gemfile.lock index 782fccba242..0940b639e89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,7 +43,7 @@ GEM activemodel (>= 4.1, < 6) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - active_record_query_trace (1.5.4) + active_record_query_trace (1.6) activejob (5.2.2) activesupport (= 5.2.2) globalid (>= 0.3.6) @@ -656,7 +656,7 @@ PLATFORMS DEPENDENCIES active_model_serializers (~> 0.10) - active_record_query_trace (~> 1.5) + active_record_query_trace (~> 1.6) addressable (~> 2.6) annotate (~> 2.7) aws-sdk-s3 (~> 1.30) From 7f32d675b05b012a80c2b34c07d361ec8d596bf3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 03:57:46 +0100 Subject: [PATCH 7/9] Render unicode emoji in polls using emoji pack Port 4407f07014096bcbaf5a06015a5791984282846d to glitch-soc --- .../flavours/glitch/actions/importer/index.js | 4 ++-- .../flavours/glitch/actions/importer/normalizer.js | 11 +++++++++++ app/javascript/flavours/glitch/components/poll.js | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js index abadee8173f..e990dc04cb6 100644 --- a/app/javascript/flavours/glitch/actions/importer/index.js +++ b/app/javascript/flavours/glitch/actions/importer/index.js @@ -1,4 +1,4 @@ -import { normalizeAccount, normalizeStatus } from './normalizer'; +import { normalizeAccount, normalizeStatus, normalizePoll } from './normalizer'; export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT'; export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT'; @@ -71,7 +71,7 @@ export function importFetchedStatuses(statuses) { } if (status.poll && status.poll.id) { - pushUnique(polls, status.poll); + pushUnique(polls, normalizePoll(status.poll)); } } diff --git a/app/javascript/flavours/glitch/actions/importer/normalizer.js b/app/javascript/flavours/glitch/actions/importer/normalizer.js index f57fb70b4e1..ccd84364e83 100644 --- a/app/javascript/flavours/glitch/actions/importer/normalizer.js +++ b/app/javascript/flavours/glitch/actions/importer/normalizer.js @@ -65,3 +65,14 @@ export function normalizeStatus(status, normalOldStatus) { return normalStatus; } + +export function normalizePoll(poll) { + const normalPoll = { ...poll }; + + normalPoll.options = poll.options.map(option => ({ + ...option, + title_emojified: emojify(escapeTextContentForBrowser(option.title)), + })); + + return normalPoll; +} diff --git a/app/javascript/flavours/glitch/components/poll.js b/app/javascript/flavours/glitch/components/poll.js index 182491af865..c52445c86f0 100644 --- a/app/javascript/flavours/glitch/components/poll.js +++ b/app/javascript/flavours/glitch/components/poll.js @@ -120,7 +120,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - {option.get('title')} + ); From 94f1a751bf0313249d891e760dc758e621f1b9ad Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 04:54:32 +0100 Subject: [PATCH 8/9] Avoid line breaks in poll options Port 57643557b64bc1853c4aeb65fc652dac3467fa18 to glitch-soc --- app/javascript/flavours/glitch/styles/polls.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/javascript/flavours/glitch/styles/polls.scss b/app/javascript/flavours/glitch/styles/polls.scss index 7c6e61d6301..ce324b36ea8 100644 --- a/app/javascript/flavours/glitch/styles/polls.scss +++ b/app/javascript/flavours/glitch/styles/polls.scss @@ -5,6 +5,7 @@ li { margin-bottom: 10px; position: relative; + height: 18px + 12px; } &__chart { @@ -27,6 +28,9 @@ padding: 6px 0; line-height: 18px; cursor: default; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; input[type=radio], input[type=checkbox] { From 94a0149ff3e455792050e790d397d1d4d2c2d851 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 05:35:52 +0100 Subject: [PATCH 9/9] Fix poll options not rendering text after vote/refresh Port fd128b9c7aa5c71adbfc2e223212514c0baee675 to glitch-soc --- .../flavours/glitch/actions/importer/index.js | 6 ++++++ app/javascript/flavours/glitch/actions/polls.js | 11 +++++++++-- app/javascript/flavours/glitch/components/poll.js | 4 +++- app/javascript/flavours/glitch/reducers/polls.js | 4 ---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js index e990dc04cb6..f4372fb31d0 100644 --- a/app/javascript/flavours/glitch/actions/importer/index.js +++ b/app/javascript/flavours/glitch/actions/importer/index.js @@ -82,3 +82,9 @@ export function importFetchedStatuses(statuses) { dispatch(importStatuses(normalStatuses)); }; } + +export function importFetchedPoll(poll) { + return dispatch => { + dispatch(importPolls([normalizePoll(poll)])); + }; +} diff --git a/app/javascript/flavours/glitch/actions/polls.js b/app/javascript/flavours/glitch/actions/polls.js index bee4c48a692..8e8b82df5d0 100644 --- a/app/javascript/flavours/glitch/actions/polls.js +++ b/app/javascript/flavours/glitch/actions/polls.js @@ -1,4 +1,5 @@ import api from '../api'; +import { importFetchedPoll } from './importer'; export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS'; @@ -12,7 +13,10 @@ export const vote = (pollId, choices) => (dispatch, getState) => { dispatch(voteRequest()); api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices }) - .then(({ data }) => dispatch(voteSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(voteSuccess(data)); + }) .catch(err => dispatch(voteFail(err))); }; @@ -20,7 +24,10 @@ export const fetchPoll = pollId => (dispatch, getState) => { dispatch(fetchPollRequest()); api(getState).get(`/api/v1/polls/${pollId}`) - .then(({ data }) => dispatch(fetchPollSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(fetchPollSuccess(data)); + }) .catch(err => dispatch(fetchPollFail(err))); }; diff --git a/app/javascript/flavours/glitch/components/poll.js b/app/javascript/flavours/glitch/components/poll.js index c52445c86f0..bfff7b60116 100644 --- a/app/javascript/flavours/glitch/components/poll.js +++ b/app/javascript/flavours/glitch/components/poll.js @@ -7,6 +7,8 @@ import classNames from 'classnames'; import { vote, fetchPoll } from 'mastodon/actions/polls'; import Motion from 'mastodon/features/ui/util/optional_motion'; import spring from 'react-motion/lib/spring'; +import escapeTextContentForBrowser from 'escape-html'; +import emojify from 'mastodon/features/emoji/emoji'; const messages = defineMessages({ moments: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' }, @@ -120,7 +122,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - + ); diff --git a/app/javascript/flavours/glitch/reducers/polls.js b/app/javascript/flavours/glitch/reducers/polls.js index 53d9b1d8cb4..9956cf83f60 100644 --- a/app/javascript/flavours/glitch/reducers/polls.js +++ b/app/javascript/flavours/glitch/reducers/polls.js @@ -1,4 +1,3 @@ -import { POLL_VOTE_SUCCESS, POLL_FETCH_SUCCESS } from 'mastodon/actions/polls'; import { POLLS_IMPORT } from 'mastodon/actions/importer'; import { Map as ImmutableMap, fromJS } from 'immutable'; @@ -10,9 +9,6 @@ export default function polls(state = initialState, action) { switch(action.type) { case POLLS_IMPORT: return importPolls(state, action.polls); - case POLL_VOTE_SUCCESS: - case POLL_FETCH_SUCCESS: - return importPolls(state, [action.poll]); default: return state; }