Bump to media attachments max on poll (disabled now)

This commit is contained in:
KMY 2023-05-12 15:47:40 +09:00
parent ec0ed1cfd8
commit 2a54b76823
5 changed files with 11 additions and 4 deletions

View file

@ -36,6 +36,7 @@ class MediaAttachment < ApplicationRecord
include RoutingHelper
LOCAL_STATUS_ATTACHMENT_MAX = 4
LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL = 4
ACTIVITYPUB_STATUS_ATTACHMENT_MAX = 16
enum type: { image: 0, gifv: 1, video: 2, unknown: 3, audio: 4 }

View file

@ -55,6 +55,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
statuses: {
max_characters: StatusLengthValidator::MAX_CHARS,
max_media_attachments: MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX,
max_media_attachments_with_poll: MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL,
max_media_attachments_from_activitypub: MediaAttachment::ACTIVITYPUB_STATUS_ATTACHMENT_MAX,
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
},

View file

@ -65,6 +65,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
statuses: {
max_characters: StatusLengthValidator::MAX_CHARS,
max_media_attachments: MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX,
max_media_attachments_with_poll: MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL,
max_media_attachments_from_activitypub: MediaAttachment::ACTIVITYPUB_STATUS_ATTACHMENT_MAX,
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
},

View file

@ -155,9 +155,11 @@ class PostStatusService < BaseService
return
end
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX
media_max = @options[:poll] ? MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL : MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX).map(&:to_i))
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > media_max
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(media_max).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.not_ready') if @media.any?(&:not_processed?)

View file

@ -72,9 +72,11 @@ 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 > MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX || @options[:poll].present?
media_max = @options[:poll] ? MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL : MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX).map(&:to_i)).to_a
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > media_max
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(media_max).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.not_ready') if media_attachments.any?(&:not_processed?)