Fix post edits not being forwarded as expected (#26936)
This commit is contained in:
		
							parent
							
								
									5fd89e53d2
								
							
						
					
					
						commit
						d6c0ae995c
					
				@ -28,6 +28,6 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return if @status.nil?
 | 
					    return if @status.nil?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ActivityPub::ProcessStatusUpdateService.new.call(@status, @object, request_id: @options[:request_id])
 | 
					    ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,6 @@ class ActivityPub::FetchRemotePollService < BaseService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return unless supported_context?(json)
 | 
					    return unless supported_context?(json)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json)
 | 
					    ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json, json)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -5,10 +5,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
 | 
				
			|||||||
  include Redisable
 | 
					  include Redisable
 | 
				
			||||||
  include Lockable
 | 
					  include Lockable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def call(status, json, request_id: nil)
 | 
					  def call(status, activity_json, object_json, request_id: nil)
 | 
				
			||||||
    raise ArgumentError, 'Status has unsaved changes' if status.changed?
 | 
					    raise ArgumentError, 'Status has unsaved changes' if status.changed?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @json                      = json
 | 
					    @activity_json             = activity_json
 | 
				
			||||||
 | 
					    @json                      = object_json
 | 
				
			||||||
    @status_parser             = ActivityPub::Parser::StatusParser.new(@json)
 | 
					    @status_parser             = ActivityPub::Parser::StatusParser.new(@json)
 | 
				
			||||||
    @uri                       = @status_parser.uri
 | 
					    @uri                       = @status_parser.uri
 | 
				
			||||||
    @status                    = status
 | 
					    @status                    = status
 | 
				
			||||||
@ -308,6 +309,6 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def forwarder
 | 
					  def forwarder
 | 
				
			||||||
    @forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
 | 
					    @forwarder ||= ActivityPub::Forwarder.new(@account, @activity_json, @status)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -41,12 +41,12 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  describe '#call' do
 | 
					  describe '#call' do
 | 
				
			||||||
    it 'updates text' do
 | 
					    it 'updates text' do
 | 
				
			||||||
      subject.call(status, json)
 | 
					      subject.call(status, json, json)
 | 
				
			||||||
      expect(status.reload.text).to eq 'Hello universe'
 | 
					      expect(status.reload.text).to eq 'Hello universe'
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it 'updates content warning' do
 | 
					    it 'updates content warning' do
 | 
				
			||||||
      subject.call(status, json)
 | 
					      subject.call(status, json, json)
 | 
				
			||||||
      expect(status.reload.spoiler_text).to eq 'Show more'
 | 
					      expect(status.reload.spoiler_text).to eq 'Show more'
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,7 +64,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -87,7 +87,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -135,7 +135,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -188,7 +188,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -216,11 +216,11 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
        expect { subject.call(status, json) }.not_to change { status.reload.edits.pluck(&:id) }
 | 
					        expect { subject.call(status, json, json) }.to_not(change { status.reload.edits.pluck(&:id) })
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not update the text, spoiler_text or edited_at' do
 | 
					      it 'does not update the text, spoiler_text or edited_at' do
 | 
				
			||||||
        expect { subject.call(status, json) }.not_to change { s = status.reload; [s.text, s.spoiler_text, s.edited_at] }
 | 
					        expect { subject.call(status, json, json) }.to_not(change { s = status.reload; [s.text, s.spoiler_text, s.edited_at] })
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -235,7 +235,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -259,7 +259,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        status.update(ordered_media_attachment_ids: nil)
 | 
					        status.update(ordered_media_attachment_ids: nil)
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'does not create any edits' do
 | 
					      it 'does not create any edits' do
 | 
				
			||||||
@ -273,7 +273,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    context 'originally without tags' do
 | 
					    context 'originally without tags' do
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'updates tags' do
 | 
					      it 'updates tags' do
 | 
				
			||||||
@ -299,7 +299,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'updates tags' do
 | 
					      it 'updates tags' do
 | 
				
			||||||
@ -309,7 +309,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    context 'originally without mentions' do
 | 
					    context 'originally without mentions' do
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'updates mentions' do
 | 
					      it 'updates mentions' do
 | 
				
			||||||
@ -321,7 +321,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      let(:mentions) { [alice, bob] }
 | 
					      let(:mentions) { [alice, bob] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'updates mentions' do
 | 
					      it 'updates mentions' do
 | 
				
			||||||
@ -332,7 +332,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
    context 'originally without media attachments' do
 | 
					    context 'originally without media attachments' do
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png'))
 | 
					        stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png'))
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      let(:payload) do
 | 
					      let(:payload) do
 | 
				
			||||||
@ -382,7 +382,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        allow(RedownloadMediaWorker).to receive(:perform_async)
 | 
					        allow(RedownloadMediaWorker).to receive(:perform_async)
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'updates the existing media attachment in-place' do
 | 
					      it 'updates the existing media attachment in-place' do
 | 
				
			||||||
@ -410,7 +410,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      before do
 | 
					      before do
 | 
				
			||||||
        poll = Fabricate(:poll, status: status)
 | 
					        poll = Fabricate(:poll, status: status)
 | 
				
			||||||
        status.update(preloadable_poll: poll)
 | 
					        status.update(preloadable_poll: poll)
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'removes poll' do
 | 
					      it 'removes poll' do
 | 
				
			||||||
@ -440,7 +440,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before do
 | 
					      before do
 | 
				
			||||||
        subject.call(status, json)
 | 
					        subject.call(status, json, json)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'creates a poll' do
 | 
					      it 'creates a poll' do
 | 
				
			||||||
@ -456,12 +456,12 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it 'creates edit history' do
 | 
					    it 'creates edit history' do
 | 
				
			||||||
      subject.call(status, json)
 | 
					      subject.call(status, json, json)
 | 
				
			||||||
      expect(status.edits.reload.map(&:text)).to eq ['Hello world', 'Hello universe']
 | 
					      expect(status.edits.reload.map(&:text)).to eq ['Hello world', 'Hello universe']
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it 'sets edited timestamp' do
 | 
					    it 'sets edited timestamp' do
 | 
				
			||||||
      subject.call(status, json)
 | 
					      subject.call(status, json, json)
 | 
				
			||||||
      expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC'
 | 
					      expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC'
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user