From 849a9ea0de0445e53c28740cc4efa8e4ab2f16f7 Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 28 Nov 2023 23:33:17 -0600 Subject: [PATCH 1/2] Allow posting media alongside polls --- app/javascript/flavours/glitch/actions/compose.js | 6 ------ .../features/compose/containers/poll_button_container.js | 2 +- .../features/compose/containers/upload_button_container.js | 3 +-- app/services/post_status_service.rb | 2 +- app/services/update_status_service.rb | 2 +- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 61245acdba9873..1e87e1b009a315 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -88,7 +88,6 @@ export const COMPOSE_FOCUS = 'COMPOSE_FOCUS'; 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.' }, open: { id: 'compose.published.open', defaultMessage: 'Open' }, published: { id: 'compose.published.body', defaultMessage: 'Post published.' }, saved: { id: 'compose.saved.body', defaultMessage: 'Post saved.' }, @@ -322,11 +321,6 @@ export function uploadCompose(files) { return; } - if (getState().getIn(['compose', 'poll'])) { - dispatch(showAlert({ message: messages.uploadErrorPoll })); - return; - } - dispatch(uploadComposeRequest()); for (const [i, f] of Array.from(files).entries()) { diff --git a/app/javascript/flavours/glitch/features/compose/containers/poll_button_container.js b/app/javascript/flavours/glitch/features/compose/containers/poll_button_container.js index 9de388f64aab78..a9b558468b83e2 100644 --- a/app/javascript/flavours/glitch/features/compose/containers/poll_button_container.js +++ b/app/javascript/flavours/glitch/features/compose/containers/poll_button_container.js @@ -4,7 +4,7 @@ import { addPoll, removePoll } from '../../../actions/compose'; import PollButton from '../components/poll_button'; const mapStateToProps = state => ({ - disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size > 0), + disabled: state.getIn(['compose', 'is_uploading']), active: state.getIn(['compose', 'poll']) !== null, }); diff --git a/app/javascript/flavours/glitch/features/compose/containers/upload_button_container.js b/app/javascript/flavours/glitch/features/compose/containers/upload_button_container.js index 2e835464b85119..cd98b9876df3b8 100644 --- a/app/javascript/flavours/glitch/features/compose/containers/upload_button_container.js +++ b/app/javascript/flavours/glitch/features/compose/containers/upload_button_container.js @@ -5,7 +5,6 @@ import { openModal } from '../../../actions/modal'; import UploadButton from '../components/upload_button'; const mapStateToProps = state => { - const isPoll = state.getIn(['compose', 'poll']) !== null; const isUploading = state.getIn(['compose', 'is_uploading']); const readyAttachmentsSize = state.getIn(['compose', 'media_attachments']).size ?? 0; const pendingAttachmentsSize = state.getIn(['compose', 'pending_media_attachments']).size ?? 0; @@ -14,7 +13,7 @@ const mapStateToProps = state => { const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type'))); return { - disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio, + disabled: isUploading || isOverLimit || hasVideoOrAudio, resetFileKey: state.getIn(['compose', 'resetFileKey']), }; }; diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 71e44c23a6d430..473ed4055e7092 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -146,7 +146,7 @@ def validate_media! return end - raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > Status::MEDIA_ATTACHMENTS_LIMIT || @options[:poll].present? + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > Status::MEDIA_ATTACHMENTS_LIMIT @media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i)) diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 70f5959f21a771..7f7f389bee128a 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -70,7 +70,7 @@ def update_media_attachments! 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 > Status::MEDIA_ATTACHMENTS_LIMIT || @options[:poll].present? + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > Status::MEDIA_ATTACHMENTS_LIMIT media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i)).to_a From c1520e38aac5e44b752c037598a9e9a558b25513 Mon Sep 17 00:00:00 2001 From: Essem Date: Sat, 6 Jan 2024 23:28:58 -0600 Subject: [PATCH 2/2] Expose poll media support in instance api endpoint --- app/serializers/rest/instance_serializer.rb | 1 + app/serializers/rest/v1/instance_serializer.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index cc557023ba5540..a07c791a64e4ec 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -74,6 +74,7 @@ def configuration }, polls: { + allow_media: true, max_options: PollValidator::MAX_OPTIONS, max_characters_per_option: PollValidator::MAX_OPTION_CHARS, min_expiration: PollValidator::MIN_EXPIRATION, diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 69ffaa346f9c43..78c47e64e1dd50 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -92,6 +92,7 @@ def configuration }, polls: { + allow_media: true, max_options: PollValidator::MAX_OPTIONS, max_characters_per_option: PollValidator::MAX_OPTION_CHARS, min_expiration: PollValidator::MIN_EXPIRATION,