From e665cc68f484a5d2cbabe8dec19e523a7ad43814 Mon Sep 17 00:00:00 2001 From: fiona Date: Tue, 2 Sep 2025 12:25:55 +0000 Subject: [PATCH] Fix handling of edited status with new media and no text (#35970) --- .../process_status_update_service.rb | 2 ++ .../process_status_update_service_spec.rb | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index 362be0c8772..2e0e6e8864c 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -112,6 +112,8 @@ class ActivityPub::ProcessStatusUpdateService < BaseService @status.ordered_media_attachment_ids = @next_media_attachments.map(&:id) @media_attachments_changed = true if @status.ordered_media_attachment_ids != previous_media_attachments_ids + + @status.media_attachments.reload if @media_attachments_changed end def download_media_files! diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 74b8cef413a..9875101778f 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -343,6 +343,42 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do end end + context 'when originally without media attachments and text is removed' do + before do + stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png')) + end + + let(:payload) do + { + '@context': 'https://www.w3.org/ns/activitystreams', + id: 'foo', + type: 'Note', + content: '', + updated: '2021-09-08T22:39:25Z', + attachment: [ + { type: 'Image', mediaType: 'image/png', url: 'https://example.com/foo.png' }, + ], + } + end + + it 'updates media attachments, fetches attachment, records media and text removal in edit' do + subject.call(status, json, json) + + expect(status.reload.ordered_media_attachments.first) + .to be_present + .and(have_attributes(remote_url: 'https://example.com/foo.png')) + + expect(a_request(:get, 'https://example.com/foo.png')) + .to have_been_made + + expect(status.edits.reload.last.ordered_media_attachment_ids) + .to_not be_empty + + expect(status.edits.reload.last.text) + .to_not be_present + end + end + context 'when originally with media attachments' do let(:media_attachments) { [Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png'), Fabricate(:media_attachment, remote_url: 'https://example.com/unused.png')] }