Skip to content

Commit 925ca90

Browse files
committed
feat(9-medias): support max to 9 images
1 parent 819ede1 commit 925ca90

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

app/javascript/mastodon/actions/compose.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export function submitComposeFail(error) {
278278

279279
export function uploadCompose(files) {
280280
return function (dispatch, getState) {
281-
const uploadLimit = 4;
281+
const uploadLimit = 9;
282282
const media = getState().getIn(['compose', 'media_attachments']);
283283
const pending = getState().getIn(['compose', 'pending_media_attachments']);
284284
const progress = new Array(files.length).fill(0);
@@ -298,7 +298,7 @@ export function uploadCompose(files) {
298298
dispatch(uploadComposeRequest());
299299

300300
for (const [i, file] of Array.from(files).entries()) {
301-
if (media.size + i > 3) break;
301+
if (media.size + i > 8) break;
302302

303303
const data = new FormData();
304304
data.append('file', file);

app/javascript/mastodon/components/media_gallery.jsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ class Item extends PureComponent {
102102
height = 50;
103103
}
104104

105+
if (size > 5) {
106+
width = 100 / 3;
107+
height = 50;
108+
109+
if (size > 6) {
110+
height = 100 / 3;
111+
}
112+
}
113+
105114
if (attachment.get('description')?.length > 0) {
106115
badges.push(<span key='alt' className='media-gallery__alt__label'>ALT</span>);
107116
}
@@ -305,13 +314,13 @@ class MediaGallery extends PureComponent {
305314
style.aspectRatio = '3 / 2';
306315
}
307316

308-
const size = media.take(4).size;
317+
const size = media.take(9).size;
309318
const uncached = media.every(attachment => attachment.get('type') === 'unknown');
310319

311320
if (this.isFullSizeEligible()) {
312321
children = <Item standalone autoplay={autoplay} onClick={this.handleClick} attachment={media.get(0)} lang={lang} displayWidth={width} visible={visible} />;
313322
} else {
314-
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} />);
323+
children = media.take(9).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} />);
315324
}
316325

317326
if (uncached) {
@@ -336,6 +345,15 @@ class MediaGallery extends PureComponent {
336345
);
337346
}
338347

348+
if (size > 4) {
349+
style.gridTemplateColumns = 'repeat(3, 1fr)';
350+
style.aspectRatio = '1 /1';
351+
352+
if (size > 6) {
353+
style.gridTemplateRows = 'repeat(3, 1fr)';
354+
}
355+
}
356+
339357
return (
340358
<div className='media-gallery' style={style} ref={this.handleRef}>
341359
<div className={classNames('spoiler-button', { 'spoiler-button--minified': visible && !uncached, 'spoiler-button--click-thru': uncached })}>

app/javascript/mastodon/features/compose/containers/upload_button_container.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
import { connect } from 'react-redux';
1+
import {connect} from 'react-redux';
22

3-
import { uploadCompose } from '../../../actions/compose';
3+
import {uploadCompose} from '../../../actions/compose';
44
import UploadButton from '../components/upload_button';
55

6-
const mapStateToProps = state => ({
7-
disabled: state.getIn(['compose', 'poll']) !== null || 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')))),
8-
resetFileKey: state.getIn(['compose', 'resetFileKey']),
9-
});
6+
const mapStateToProps = state => {
7+
const isPoll = state.getIn(['compose', 'poll']) !== null;
8+
const isUploading = state.getIn(['compose', 'is_uploading']);
9+
const readyAttachmentsSize = state.getIn(['compose', 'media_attachments']).size ?? 0;
10+
const pendingAttachmentsSize = state.getIn(['compose', 'pending_media_attachments']).size ?? 0;
11+
const attachmentsSize = readyAttachmentsSize + pendingAttachmentsSize;
12+
const isOverLimit = attachmentsSize > 8;
13+
const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')));
14+
15+
return {
16+
disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio,
17+
resetFileKey: state.getIn(['compose', 'resetFileKey']),
18+
};
19+
};
1020

1121
const mapDispatchToProps = dispatch => ({
1222

13-
onSelectFile (files) {
23+
onSelectFile(files) {
1424
dispatch(uploadCompose(files));
1525
},
1626

app/lib/activitypub/activity/create.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def find_existing_status
110110
def process_status_params
111111
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url, object: @object)
112112

113-
attachment_ids = process_attachments.take(4).map(&:id)
113+
attachment_ids = process_attachments.take(9).map(&:id)
114114

115115
@params = {
116116
uri: @status_parser.uri,
@@ -260,7 +260,7 @@ def process_attachments
260260
as_array(@object['attachment']).each do |attachment|
261261
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
262262

263-
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= 4
263+
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= 9
264264

265265
begin
266266
media_attachment = MediaAttachment.create(

app/services/post_status_service.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def validate_media!
130130
return
131131
end
132132

133-
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4 || @options[:poll].present?
133+
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 9 || @options[:poll].present?
134134

135-
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))
135+
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(9).map(&:to_i))
136136

137137
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?)
138138
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if @media.any?(&:not_processed?)

0 commit comments

Comments
 (0)