Support 5 or more media_attachments from activitypub
This commit is contained in:
parent
21899ccf3f
commit
1502668ee5
11 changed files with 41 additions and 13 deletions
|
@ -278,7 +278,7 @@ export function uploadCompose(files) {
|
|||
dispatch(uploadComposeRequest());
|
||||
|
||||
for (const [i, f] of Array.from(files).entries()) {
|
||||
if (media.size + i > 3) break;
|
||||
if (media.size + i >= 4) break;
|
||||
|
||||
resizeImage(f).then(file => {
|
||||
const data = new FormData();
|
||||
|
|
|
@ -66,7 +66,7 @@ export function normalizeStatus(status, normalOldStatus) {
|
|||
normalStatus.filtered = status.filtered.map(normalizeFilterResult);
|
||||
}
|
||||
|
||||
if (status.emoji_reactions && normalOldStatus) {
|
||||
if (status.emoji_reactions && normalOldStatus && normalOldStatus.get('emoji_reactions')) {
|
||||
normalStatus.emoji_reactions = normalizeEmojiReactions(normalOldStatus.get('emoji_reactions').toArray());
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,16 @@ class Item extends React.PureComponent {
|
|||
height = 50;
|
||||
}
|
||||
|
||||
if (size === 5 || size === 6) {
|
||||
height = 33;
|
||||
}
|
||||
if (size === 7 || size === 8) {
|
||||
height = 25;
|
||||
}
|
||||
if ((size === 5 && index === 4) || (size === 7 && index === 6)) {
|
||||
width = 100;
|
||||
}
|
||||
|
||||
if (size === 2) {
|
||||
if (index === 0) {
|
||||
right = '2px';
|
||||
|
@ -128,6 +138,21 @@ class Item extends React.PureComponent {
|
|||
} else {
|
||||
top = '2px';
|
||||
}
|
||||
} else {
|
||||
if (index % 2 === 0) {
|
||||
right = '2px';
|
||||
}
|
||||
|
||||
if (index % 2 === 1) {
|
||||
left = '2px';
|
||||
}
|
||||
|
||||
if (index >= 2) {
|
||||
top = '2px';
|
||||
}
|
||||
if (index < size - 1) {
|
||||
bottom = '2px';
|
||||
}
|
||||
}
|
||||
|
||||
let thumbnail = '';
|
||||
|
@ -332,13 +357,13 @@ class MediaGallery extends React.PureComponent {
|
|||
style.height = height;
|
||||
}
|
||||
|
||||
const size = media.take(4).size;
|
||||
const size = media.take(8).size;
|
||||
const uncached = media.every(attachment => attachment.get('type') === 'unknown');
|
||||
|
||||
if (standalone && 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(8).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) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import UploadButton from '../components/upload_button';
|
|||
import { uploadCompose } from '../../../actions/compose';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size + state.getIn(['compose', 'pending_media_attachments']) > 3 || state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')))),
|
||||
disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size + state.getIn(['compose', 'pending_media_attachments']) >= 4 || state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')))),
|
||||
unavailable: state.getIn(['compose', 'poll']) !== null,
|
||||
resetFileKey: state.getIn(['compose', 'resetFileKey']),
|
||||
});
|
||||
|
|
|
@ -131,7 +131,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
searchability: searchability,
|
||||
thread: replied_to_status,
|
||||
conversation: conversation_from_uri(@object['conversation']),
|
||||
media_attachment_ids: process_attachments.take(4).map(&:id),
|
||||
media_attachment_ids: process_attachments.take(MediaAttachment::ACTIVITYPUB_STATUS_ATTACHMENT_MAX).map(&:id),
|
||||
poll: process_poll,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -35,6 +35,9 @@ class MediaAttachment < ApplicationRecord
|
|||
include Attachmentable
|
||||
include RoutingHelper
|
||||
|
||||
LOCAL_STATUS_ATTACHMENT_MAX = 4
|
||||
ACTIVITYPUB_STATUS_ATTACHMENT_MAX = 8
|
||||
|
||||
enum type: { :image => 0, :gifv => 1, :video => 2, :unknown => 3, :audio => 4 }
|
||||
enum processing: { :queued => 0, :in_progress => 1, :complete => 2, :failed => 3 }, _prefix: true
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
|||
|
||||
statuses: {
|
||||
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||
max_media_attachments: 4,
|
||||
max_media_attachments: MediaAttachment::LOCAL_STATUS_ATTACHMENT_MAX,
|
||||
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::LOCAL_STATUS_ATTACHMENT_MAX,
|
||||
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
|
||||
},
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
as_array(@json['attachment']).each do |attachment|
|
||||
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
||||
|
||||
next if media_attachment_parser.remote_url.blank? || @next_media_attachments.size > 4
|
||||
next if media_attachment_parser.remote_url.blank? || @next_media_attachments.size > MediaAttachment::ACTIVITYPUB_STATUS_ATTACHMENT_MAX
|
||||
|
||||
begin
|
||||
media_attachment = previous_media_attachments.find { |previous_media_attachment| previous_media_attachment.remote_url == media_attachment_parser.remote_url }
|
||||
|
|
|
@ -150,9 +150,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::LOCAL_STATUS_ATTACHMENT_MAX || @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::LOCAL_STATUS_ATTACHMENT_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?)
|
||||
|
|
|
@ -71,9 +71,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::LOCAL_STATUS_ATTACHMENT_MAX || @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::LOCAL_STATUS_ATTACHMENT_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?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue