mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-12 04:31:11 +00:00
Merge ee9a40bec0
into fbe9728f36
This commit is contained in:
commit
c31e92d01f
|
@ -17,6 +17,14 @@ import { formatTime } from 'mastodon/features/video';
|
||||||
|
|
||||||
import { autoPlayGif, displayMedia, useBlurhash } from '../initial_state';
|
import { autoPlayGif, displayMedia, useBlurhash } from '../initial_state';
|
||||||
|
|
||||||
|
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 {
|
class Item extends PureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -93,14 +101,18 @@ class Item extends PureComponent {
|
||||||
let badges = [], thumbnail;
|
let badges = [], thumbnail;
|
||||||
|
|
||||||
let width = 50;
|
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;
|
width = 100;
|
||||||
}
|
height = 100;
|
||||||
|
} else if (size === 2 || index < largeCount + mediumCount) {
|
||||||
if (size === 4 || (size === 3 && index > 0)) {
|
height = 100;
|
||||||
height = 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = attachment.getIn(['translation', 'description']) || attachment.get('description');
|
const description = attachment.getIn(['translation', 'description']) || attachment.get('description');
|
||||||
|
@ -308,6 +320,11 @@ class MediaGallery extends PureComponent {
|
||||||
if (this.isFullSizeEligible()) {
|
if (this.isFullSizeEligible()) {
|
||||||
style.aspectRatio = `${this.props.media.getIn([0, 'meta', 'small', 'aspect'])}`;
|
style.aspectRatio = `${this.props.media.getIn([0, 'meta', 'small', 'aspect'])}`;
|
||||||
} else {
|
} 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';
|
style.aspectRatio = '3 / 2';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
object: @object
|
object: @object
|
||||||
)
|
)
|
||||||
|
|
||||||
attachment_ids = process_attachments.take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:id)
|
attachment_ids = process_attachments.take(Status::REMOTE_MEDIA_ATTACHMENTS_LIMIT).map(&:id)
|
||||||
|
|
||||||
@params = {
|
@params = {
|
||||||
uri: @status_parser.uri,
|
uri: @status_parser.uri,
|
||||||
|
@ -287,7 +287,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
as_array(@object['attachment']).each do |attachment|
|
as_array(@object['attachment']).each do |attachment|
|
||||||
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
||||||
|
|
||||||
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= Status::MEDIA_ATTACHMENTS_LIMIT
|
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= Status::REMOTE_MEDIA_ATTACHMENTS_LIMIT
|
||||||
|
|
||||||
begin
|
begin
|
||||||
media_attachment = MediaAttachment.create(
|
media_attachment = MediaAttachment.create(
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Status < ApplicationRecord
|
||||||
include Status::Visibility
|
include Status::Visibility
|
||||||
|
|
||||||
MEDIA_ATTACHMENTS_LIMIT = 4
|
MEDIA_ATTACHMENTS_LIMIT = 4
|
||||||
|
REMOTE_MEDIA_ATTACHMENTS_LIMIT = 16
|
||||||
|
|
||||||
QUOTE_APPROVAL_POLICY_FLAGS = {
|
QUOTE_APPROVAL_POLICY_FLAGS = {
|
||||||
unknown: (1 << 0),
|
unknown: (1 << 0),
|
||||||
|
@ -278,6 +279,10 @@ class Status < ApplicationRecord
|
||||||
@emojis = CustomEmoji.from_text(fields.join(' '), account.domain)
|
@emojis = CustomEmoji.from_text(fields.join(' '), account.domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def media_attachments_limit
|
||||||
|
local? ? MEDIA_ATTACHMENTS_LIMIT : REMOTE_MEDIA_ATTACHMENTS_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
def ordered_media_attachments
|
def ordered_media_attachments
|
||||||
if ordered_media_attachment_ids.nil?
|
if ordered_media_attachment_ids.nil?
|
||||||
# NOTE: sort Ruby-side to avoid hitting the database when the status is
|
# NOTE: sort Ruby-side to avoid hitting the database when the status is
|
||||||
|
@ -286,7 +291,7 @@ class Status < ApplicationRecord
|
||||||
else
|
else
|
||||||
map = media_attachments.index_by(&:id)
|
map = media_attachments.index_by(&:id)
|
||||||
ordered_media_attachment_ids.filter_map { |media_attachment_id| map[media_attachment_id] }
|
ordered_media_attachment_ids.filter_map { |media_attachment_id| map[media_attachment_id] }
|
||||||
end.take(MEDIA_ATTACHMENTS_LIMIT)
|
end.take(media_attachments_limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies_count
|
def replies_count
|
||||||
|
|
|
@ -61,7 +61,7 @@ class StatusEdit < ApplicationRecord
|
||||||
map = status.media_attachments.index_by(&:id)
|
map = status.media_attachments.index_by(&:id)
|
||||||
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
||||||
end
|
end
|
||||||
end.take(Status::MEDIA_ATTACHMENTS_LIMIT)
|
end.take(status.media_attachments_limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def proper
|
def proper
|
||||||
|
|
|
@ -82,7 +82,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
||||||
as_array(@json['attachment']).each do |attachment|
|
as_array(@json['attachment']).each do |attachment|
|
||||||
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
||||||
|
|
||||||
next if media_attachment_parser.remote_url.blank? || @next_media_attachments.size > Status::MEDIA_ATTACHMENTS_LIMIT
|
next if media_attachment_parser.remote_url.blank? || @next_media_attachments.size > Status::REMOTE_MEDIA_ATTACHMENTS_LIMIT
|
||||||
|
|
||||||
begin
|
begin
|
||||||
media_attachment = previous_media_attachments.find { |previous_media_attachment| previous_media_attachment.remote_url == media_attachment_parser.remote_url }
|
media_attachment = previous_media_attachments.find { |previous_media_attachment| previous_media_attachment.remote_url == media_attachment_parser.remote_url }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user