mirror of
https://github.com/mastodon/mastodon.git
synced 2024-05-19 10:28:08 +00:00
Merge 56ccdc022f
into 5cd13ee4f1
This commit is contained in:
commit
99295f0715
|
@ -21,6 +21,14 @@ const messages = defineMessages({
|
|||
toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: '{number, plural, one {Hide image} other {Hide images}}' },
|
||||
});
|
||||
|
||||
const colCount = function(size) {
|
||||
return Math.max(Math.ceil(Math.sqrt(size)), 2);
|
||||
};
|
||||
|
||||
const rowCount = function(size) {
|
||||
return Math.ceil(size / colCount(size));
|
||||
};
|
||||
|
||||
class Item extends PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
|
@ -92,14 +100,18 @@ class Item extends PureComponent {
|
|||
let badges = [], thumbnail;
|
||||
|
||||
let width = 50;
|
||||
let height = 100;
|
||||
let height = 50;
|
||||
|
||||
if (size === 1) {
|
||||
const cols = colCount(size);
|
||||
const remaining = (-size % cols + cols) % cols;
|
||||
const largeCount = Math.floor(remaining / 3); // width=2, height=2
|
||||
const mediumCount = remaining % 3; // height=2
|
||||
|
||||
if (size === 1 || index < largeCount) {
|
||||
width = 100;
|
||||
}
|
||||
|
||||
if (size === 4 || (size === 3 && index > 0)) {
|
||||
height = 50;
|
||||
height = 100;
|
||||
} else if (size === 2 || index < largeCount + mediumCount) {
|
||||
height = 100;
|
||||
}
|
||||
|
||||
if (attachment.get('description')?.length > 0) {
|
||||
|
@ -302,16 +314,21 @@ class MediaGallery extends PureComponent {
|
|||
if (this.isFullSizeEligible()) {
|
||||
style.aspectRatio = `${this.props.media.getIn([0, 'meta', 'small', 'aspect'])}`;
|
||||
} else {
|
||||
const cols = colCount(media.size);
|
||||
const rows = rowCount(media.size);
|
||||
style.gridTemplateColumns = `repeat(${cols}, 1fr)`;
|
||||
style.gridTemplateRows = `repeat(${rows}, 1fr)`;
|
||||
|
||||
style.aspectRatio = '3 / 2';
|
||||
}
|
||||
|
||||
const size = media.take(4).size;
|
||||
const size = media.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.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) {
|
||||
|
|
|
@ -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(16).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 >= 16
|
||||
|
||||
begin
|
||||
media_attachment = MediaAttachment.create(
|
||||
|
|
|
@ -73,7 +73,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 > 16
|
||||
|
||||
begin
|
||||
media_attachment = previous_media_attachments.find { |previous_media_attachment| previous_media_attachment.remote_url == media_attachment_parser.remote_url }
|
||||
|
|
Loading…
Reference in a new issue