Skip to content

Commit

Permalink
Fix attachments of edited statuses not being fetched (mastodon#21565) (
Browse files Browse the repository at this point in the history
…mastodon#23485)

* Fix attachments of edited statuses not being fetched

* Fix tests
  • Loading branch information
ClearlyClaire authored and atsu1125 committed Feb 17, 2023
1 parent f93dc5b commit d1536cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ def update_media_attachments!

next if unsupported_media_type?(media_attachment_parser.file_content_type) || skip_download?

RedownloadMediaWorker.perform_async(media_attachment.id) if media_attachment.remote_url_previously_changed? || media_attachment.thumbnail_remote_url_previously_changed?
begin
media_attachment.download_file! if media_attachment.remote_url_previously_changed?
media_attachment.download_thumbnail! if media_attachment.thumbnail_remote_url_previously_changed?
media_attachment.save
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError
RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id)
end
rescue Addressable::URI::InvalidURIError => e
Rails.logger.debug "Invalid URL in attachment: #{e}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

context 'originally without media attachments' do
before do
allow(RedownloadMediaWorker).to receive(:perform_async)
stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png'))
subject.call(status, json)
end

Expand All @@ -130,8 +130,8 @@
expect(media_attachment.remote_url).to eq 'https://example.com/foo.png'
end

it 'queues download of media attachments' do
expect(RedownloadMediaWorker).to have_received(:perform_async)
it 'fetches the attachment' do
expect(a_request(:get, 'https://example.com/foo.png')).to have_been_made
end

it 'records media change in edit' do
Expand Down

0 comments on commit d1536cf

Please sign in to comment.