Skip to content

Commit

Permalink
Fix post edits not being forwarded as expected (mastodon#26936)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Sep 15, 2023
1 parent 2a4fcc5 commit 6273416
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def update_status

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
2 changes: 1 addition & 1 deletion app/services/activitypub/fetch_remote_poll_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def call(poll, on_behalf_of = nil)

return unless supported_context?(json)

ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json)
ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json, json)
end
end
7 changes: 4 additions & 3 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
include Redisable
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?

@json = json
@activity_json = activity_json
@json = object_json
@status_parser = ActivityPub::Parser::StatusParser.new(@json)
@uri = @status_parser.uri
@status = status
Expand Down Expand Up @@ -306,6 +307,6 @@ def forward_activity!
end

def forwarder
@forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
@forwarder ||= ActivityPub::Forwarder.new(@account, @activity_json, @status)
end
end
40 changes: 20 additions & 20 deletions spec/services/activitypub/process_status_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def poll_option_json(name, votes)

describe '#call' do
it 'updates text' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.reload.text).to eq 'Hello universe'
end

it 'updates content warning' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.reload.spoiler_text).to eq 'Show more'
end

Expand All @@ -64,7 +64,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -87,7 +87,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -134,7 +134,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -186,7 +186,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -214,11 +214,11 @@ def poll_option_json(name, votes)
end

it 'does not create any edits' do
expect { subject.call(status, json) }.to_not(change { status.reload.edits.pluck(&:id) })
expect { subject.call(status, json, json) }.to_not(change { status.reload.edits.pluck(&:id) })
end

it 'does not update the text, spoiler_text or edited_at' do
expect { subject.call(status, json) }.to_not(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

Expand All @@ -233,7 +233,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -257,7 +257,7 @@ def poll_option_json(name, votes)

before do
status.update(ordered_media_attachment_ids: nil)
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -271,7 +271,7 @@ def poll_option_json(name, votes)

context 'when originally without tags' do
before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates tags' do
Expand All @@ -297,7 +297,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates tags' do
Expand All @@ -307,7 +307,7 @@ def poll_option_json(name, votes)

context 'when originally without mentions' do
before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates mentions' do
Expand All @@ -319,7 +319,7 @@ def poll_option_json(name, votes)
let(:mentions) { [alice, bob] }

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates mentions' do
Expand All @@ -330,7 +330,7 @@ def poll_option_json(name, votes)
context 'when originally without media attachments' do
before do
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

let(:payload) do
Expand Down Expand Up @@ -380,7 +380,7 @@ def poll_option_json(name, votes)

before do
allow(RedownloadMediaWorker).to receive(:perform_async)
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates the existing media attachment in-place' do
Expand Down Expand Up @@ -408,7 +408,7 @@ def poll_option_json(name, votes)
before do
poll = Fabricate(:poll, status: status)
status.update(preloadable_poll: poll)
subject.call(status, json)
subject.call(status, json, json)
end

it 'removes poll' do
Expand Down Expand Up @@ -438,7 +438,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'creates a poll' do
Expand All @@ -454,12 +454,12 @@ def poll_option_json(name, votes)
end

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']
end

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'
end
end
Expand Down

0 comments on commit 6273416

Please sign in to comment.