mirror of https://github.com/mastodon/mastodon
[Add] Unified the config defining max media attachments per status
This commit is contained in:
parent
90eb4a5d01
commit
7f0ca089a8
|
@ -279,7 +279,7 @@ export function submitComposeFail(error) {
|
|||
|
||||
export function uploadCompose(files) {
|
||||
return function (dispatch, getState) {
|
||||
const uploadLimit = 4;
|
||||
const uploadLimit = getState().getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments']);
|
||||
const media = getState().getIn(['compose', 'media_attachments']);
|
||||
const pending = getState().getIn(['compose', 'pending_media_attachments']);
|
||||
const progress = new Array(files.length).fill(0);
|
||||
|
@ -299,7 +299,7 @@ export function uploadCompose(files) {
|
|||
dispatch(uploadComposeRequest());
|
||||
|
||||
for (const [i, file] of Array.from(files).entries()) {
|
||||
if (media.size + i > 3) break;
|
||||
if (media.size + i > (uploadLimit - 1)) break;
|
||||
|
||||
const data = new FormData();
|
||||
data.append('file', file);
|
||||
|
|
|
@ -7,6 +7,7 @@ import classNames from 'classnames';
|
|||
|
||||
import { is } from 'immutable';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { debounce } from 'lodash';
|
||||
|
||||
|
@ -206,6 +207,10 @@ class Item extends PureComponent {
|
|||
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
maxMediaAttachments: state.getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments']),
|
||||
});
|
||||
|
||||
class MediaGallery extends PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
|
@ -221,6 +226,7 @@ class MediaGallery extends PureComponent {
|
|||
visible: PropTypes.bool,
|
||||
autoplay: PropTypes.bool,
|
||||
onToggleVisibility: PropTypes.func,
|
||||
maxMediaAttachments: PropTypes.number,
|
||||
};
|
||||
|
||||
state = {
|
||||
|
@ -291,7 +297,7 @@ class MediaGallery extends PureComponent {
|
|||
}
|
||||
|
||||
render () {
|
||||
const { media, lang, intl, sensitive, defaultWidth, autoplay } = this.props;
|
||||
const { media, lang, intl, sensitive, defaultWidth, autoplay, maxMediaAttachments } = this.props;
|
||||
const { visible } = this.state;
|
||||
const width = this.state.width || defaultWidth;
|
||||
|
||||
|
@ -305,13 +311,13 @@ class MediaGallery extends PureComponent {
|
|||
style.aspectRatio = '3 / 2';
|
||||
}
|
||||
|
||||
const size = media.take(4).size;
|
||||
const size = media.take(maxMediaAttachments).size;
|
||||
const uncached = media.every(attachment => attachment.get('type') === 'unknown');
|
||||
|
||||
if (this.isFullSizeEligible()) {
|
||||
children = <Item standalone autoplay={autoplay} onClick={this.handleClick} attachment={media.get(0)} lang={lang} displayWidth={width} visible={visible} />;
|
||||
} else {
|
||||
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} attachment={attachment} index={i} lang={lang} size={size} displayWidth={width} visible={visible || uncached} />);
|
||||
children = media.take(maxMediaAttachments).map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} attachment={attachment} index={i} lang={lang} size={size} displayWidth={width} visible={visible || uncached} />);
|
||||
}
|
||||
|
||||
if (uncached) {
|
||||
|
@ -349,4 +355,4 @@ class MediaGallery extends PureComponent {
|
|||
|
||||
}
|
||||
|
||||
export default injectIntl(MediaGallery);
|
||||
export default connect(mapStateToProps)(injectIntl(MediaGallery));
|
||||
|
|
|
@ -110,7 +110,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
def process_status_params
|
||||
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url, object: @object)
|
||||
|
||||
attachment_ids = process_attachments.take(4).map(&:id)
|
||||
attachment_ids = process_attachments.take(MediaAttachment::MAX_MEDIA_ATTACHMENTS).map(&:id)
|
||||
|
||||
@params = {
|
||||
uri: @status_parser.uri,
|
||||
|
@ -260,7 +260,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
as_array(@object['attachment']).each do |attachment|
|
||||
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
||||
|
||||
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= 4
|
||||
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= MediaAttachment::MAX_MEDIA_ATTACHMENTS
|
||||
|
||||
begin
|
||||
media_attachment = MediaAttachment.create(
|
||||
|
|
|
@ -38,6 +38,7 @@ class MediaAttachment < ApplicationRecord
|
|||
enum :processing, { queued: 0, in_progress: 1, complete: 2, failed: 3 }, prefix: true
|
||||
|
||||
MAX_DESCRIPTION_LENGTH = 1_500
|
||||
MAX_MEDIA_ATTACHMENTS = 4
|
||||
|
||||
IMAGE_LIMIT = 16.megabytes
|
||||
VIDEO_LIMIT = 99.megabytes
|
||||
|
|
|
@ -58,7 +58,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
|||
|
||||
statuses: {
|
||||
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||
max_media_attachments: 4,
|
||||
max_media_attachments: MediaAttachment::MAX_MEDIA_ATTACHMENTS,
|
||||
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
|
||||
},
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
|
|||
|
||||
statuses: {
|
||||
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||
max_media_attachments: 4,
|
||||
max_media_attachments: MediaAttachment::MAX_MEDIA_ATTACHMENTS,
|
||||
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
|
||||
},
|
||||
|
||||
|
|
|
@ -130,9 +130,9 @@ 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 > MediaAttachment::MAX_MEDIA_ATTACHMENTS || @options[:poll].present?
|
||||
|
||||
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))
|
||||
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(MediaAttachment::MAX_MEDIA_ATTACHMENTS).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?)
|
||||
|
|
|
@ -69,9 +69,9 @@ 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 > MediaAttachment::MAX_MEDIA_ATTACHMENTS || @options[:poll].present?
|
||||
|
||||
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
|
||||
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(MediaAttachment::MAX_MEDIA_ATTACHMENTS).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?)
|
||||
|
|
Loading…
Reference in New Issue