mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-26 09:03:43 +01:00
Fix media attachment order of remote posts (#28469)
This commit is contained in:
parent
a4d49c236d
commit
2bf84b93d4
3 changed files with 15 additions and 4 deletions
|
@ -110,6 +110,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
def process_status_params
|
def process_status_params
|
||||||
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url)
|
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url)
|
||||||
|
|
||||||
|
attachment_ids = process_attachments.take(4).map(&:id)
|
||||||
|
|
||||||
@params = {
|
@params = {
|
||||||
uri: @status_parser.uri,
|
uri: @status_parser.uri,
|
||||||
url: @status_parser.url || @status_parser.uri,
|
url: @status_parser.url || @status_parser.uri,
|
||||||
|
@ -125,7 +127,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
visibility: @status_parser.visibility,
|
visibility: @status_parser.visibility,
|
||||||
thread: replied_to_status,
|
thread: replied_to_status,
|
||||||
conversation: conversation_from_uri(@object['conversation']),
|
conversation: conversation_from_uri(@object['conversation']),
|
||||||
media_attachment_ids: process_attachments.take(4).map(&:id),
|
media_attachment_ids: attachment_ids,
|
||||||
|
ordered_media_attachment_ids: attachment_ids,
|
||||||
poll: process_poll,
|
poll: process_poll,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -277,7 +277,9 @@ class Status < ApplicationRecord
|
||||||
|
|
||||||
def ordered_media_attachments
|
def ordered_media_attachments
|
||||||
if ordered_media_attachment_ids.nil?
|
if ordered_media_attachment_ids.nil?
|
||||||
media_attachments
|
# NOTE: sort Ruby-side to avoid hitting the database when the status is
|
||||||
|
# not persisted to database yet
|
||||||
|
media_attachments.sort_by(&:id)
|
||||||
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] }
|
||||||
|
|
|
@ -532,15 +532,21 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||||
mediaType: 'image/png',
|
mediaType: 'image/png',
|
||||||
url: 'http://example.com/attachment.png',
|
url: 'http://example.com/attachment.png',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'Document',
|
||||||
|
mediaType: 'image/png',
|
||||||
|
url: 'http://example.com/emoji.png',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status with correctly-ordered media attachments' do
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
expect(status).to_not be_nil
|
expect(status).to_not be_nil
|
||||||
expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
|
expect(status.ordered_media_attachments.map(&:remote_url)).to eq ['http://example.com/attachment.png', 'http://example.com/emoji.png']
|
||||||
|
expect(status.ordered_media_attachment_ids).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue