From e797b43a328679c879bd7ddadfafc701daccefc8 Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 28 Nov 2023 23:33:17 -0600 Subject: [PATCH] Allow posting media alongside polls --- app/javascript/flavours/glitch/actions/compose.js | 6 ------ .../flavours/glitch/features/compose/components/options.jsx | 4 +--- .../glitch/features/compose/containers/options_container.js | 3 +-- app/services/post_status_service.rb | 2 +- app/services/update_status_service.rb | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 283928a0c0..fa31d5102b 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -88,7 +88,6 @@ export const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS'; const messages = defineMessages({ uploadErrorLimit: { id: 'upload_error.limit', defaultMessage: 'File upload limit exceeded.' }, - uploadErrorPoll: { id: 'upload_error.poll', defaultMessage: 'File upload not allowed with polls.' }, }); export const ensureComposeIsVisible = (getState, routerHistory) => { @@ -318,11 +317,6 @@ export function uploadCompose(files, alt = '') { return; } - if (getState().getIn(['compose', 'poll'])) { - dispatch(showAlert(undefined, messages.uploadErrorPoll)); - return; - } - dispatch(uploadComposeRequest()); for (const [i, f] of Array.from(files).entries()) { diff --git a/app/javascript/flavours/glitch/features/compose/components/options.jsx b/app/javascript/flavours/glitch/features/compose/components/options.jsx index f19664ea47..77c102c99c 100644 --- a/app/javascript/flavours/glitch/features/compose/components/options.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/options.jsx @@ -134,7 +134,6 @@ class ComposerOptions extends ImmutablePureComponent { advancedOptions: ImmutablePropTypes.map, disabled: PropTypes.bool, allowMedia: PropTypes.bool, - allowPoll: PropTypes.bool, hasPoll: PropTypes.bool, intl: PropTypes.object.isRequired, onChangeAdvancedOption: PropTypes.func, @@ -206,7 +205,6 @@ class ComposerOptions extends ImmutablePureComponent { contentType, disabled, allowMedia, - allowPoll, hasPoll, onChangeAdvancedOption, onChangeContentType, @@ -276,7 +274,7 @@ class ComposerOptions extends ImmutablePureComponent { {!!pollLimits && ( ['video', 'audio'].includes(item.get('type'))) : pending_media < 4), - allowPoll: !(media && !!media.size), + allowMedia: media ? media.size + pending_media < 4 && !media.some(item => ['video', 'audio'].includes(item.get('type'))) : pending_media < 4, showContentTypeChoice: state.getIn(['local_settings', 'show_content_type_choice']), contentType: state.getIn(['compose', 'content_type']), }; diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 8f5f91ec78..1c2d4d4a70 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -146,7 +146,7 @@ class PostStatusService < BaseService return end - raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4 || @options[:poll].present? + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4 @media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i)) diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index de6f1e6d1a..dc0d6f09f9 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -70,7 +70,7 @@ class UpdateStatusService < BaseService def validate_media! return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable) - raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4 || @options[:poll].present? + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4 media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i)).to_a