From bd764b24242b5c5443ad2f622647064e7d6e6f60 Mon Sep 17 00:00:00 2001 From: iLeoDo Date: Mon, 13 May 2024 21:18:07 +0100 Subject: [PATCH] [Add] Add flag indicating allowing mix media types --- .../features/compose/containers/upload_button_container.js | 4 ++-- app/models/media_attachment.rb | 2 ++ app/serializers/rest/instance_serializer.rb | 1 + app/serializers/rest/v1/instance_serializer.rb | 1 + app/services/post_status_service.rb | 2 +- app/services/update_status_service.rb | 2 +- 6 files changed, 8 insertions(+), 4 deletions(-) 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 066e185346..b96bfb3473 100644 --- a/app/javascript/mastodon/features/compose/containers/upload_button_container.js +++ b/app/javascript/mastodon/features/compose/containers/upload_button_container.js @@ -10,10 +10,10 @@ const mapStateToProps = state => { const pendingAttachmentsSize = state.getIn(['compose', 'pending_media_attachments']).size ?? 0; const attachmentsSize = readyAttachmentsSize + pendingAttachmentsSize; const isOverLimit = attachmentsSize > 3; + const allowMixMedia = state.getIn(['server', 'server', 'configuration', 'media_attachments', 'allow_mix_media'], false); const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type'))); - return { - disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio, + disabled: isPoll || isUploading || isOverLimit || (!allowMixMedia && hasVideoOrAudio), resetFileKey: state.getIn(['compose', 'resetFileKey']), }; }; diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index f53da04a97..7104738707 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -39,6 +39,8 @@ class MediaAttachment < ApplicationRecord MAX_DESCRIPTION_LENGTH = 1_500 + ALLOW_MIX_MEDIA = false + IMAGE_LIMIT = 16.megabytes VIDEO_LIMIT = 99.megabytes diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 42b73f4387..5bece44720 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -70,6 +70,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer video_size_limit: MediaAttachment::VIDEO_LIMIT, video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE, video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT, + allow_mix_media: MediaAttachment::ALLOW_MIX_MEDIA, }, polls: { diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index fdf939cfc3..2b9ecc9fa6 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -75,6 +75,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer video_size_limit: MediaAttachment::VIDEO_LIMIT, video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE, video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT, + allow_mix_media: MediaAttachment::ALLOW_MIX_MEDIA, }, polls: { diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 22a6a24afd..4438ee2051 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -134,7 +134,7 @@ class PostStatusService < BaseService @media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i)) - raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?) + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if !MediaAttachment::ALLOW_MIX_MEDIA && (@media.size > 1 && @media.find(&:audio_or_video?)) raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if @media.any?(&:not_processed?) end diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index cdfe283659..8610acc34b 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -73,7 +73,7 @@ class UpdateStatusService < BaseService 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 - raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media_attachments.size > 1 && media_attachments.find(&:audio_or_video?) + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if !MediaAttachment::ALLOW_MIX_MEDIA && (media_attachments.size > 1 && media_attachments.find(&:audio_or_video?)) raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if media_attachments.any?(&:not_processed?) media_attachments