mirror of https://github.com/mastodon/mastodon
Merge f2103d1290
into 1959365c2f
This commit is contained in:
commit
c0fff1490c
|
@ -75,6 +75,14 @@ class ActivityPub::Activity
|
|||
@object_uri ||= uri_from_bearcap(value_or_id(@object))
|
||||
end
|
||||
|
||||
def object_actor_uri
|
||||
@object_actor_uri ||= value_or_id(first_of_value(@object['attributedTo']))
|
||||
end
|
||||
|
||||
def object_actor
|
||||
@object_actor ||= Account.find_by(uri: object_actor_uri)
|
||||
end
|
||||
|
||||
def unsupported_object_type?
|
||||
@object.is_a?(String) || !(supported_object_type? || converted_object_type?)
|
||||
end
|
||||
|
@ -102,13 +110,9 @@ class ActivityPub::Activity
|
|||
return status unless status.nil?
|
||||
|
||||
# If the boosted toot is embedded and it is a self-boost, handle it like a Create
|
||||
unless unsupported_object_type?
|
||||
actor_id = value_or_id(first_of_value(@object['attributedTo']))
|
||||
|
||||
if actor_id == @account.uri
|
||||
virtual_object = { 'type' => 'Create', 'actor' => actor_id, 'object' => @object }
|
||||
return ActivityPub::Activity.factory(virtual_object, @account, request_id: @options[:request_id]).perform
|
||||
end
|
||||
if !unsupported_object_type? && (object_actor_uri == @account.uri)
|
||||
virtual_object = { 'type' => 'Create', 'actor' => object_actor_uri, 'object' => @object }
|
||||
return ActivityPub::Activity.factory(virtual_object, @account, request_id: @options[:request_id]).perform
|
||||
end
|
||||
|
||||
fetch_remote_original_status
|
||||
|
|
|
@ -26,10 +26,13 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
|||
def update_status
|
||||
return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri)
|
||||
|
||||
@status = Status.find_by(uri: object_uri, account_id: @account.id)
|
||||
|
||||
@status = Status.find_by(uri: object_uri, account_id: status_account_id)
|
||||
return if @status.nil?
|
||||
|
||||
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
|
||||
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id], activity_account_id: @account.id)
|
||||
end
|
||||
|
||||
def status_account_id
|
||||
object_actor ? object_actor.id : @account.id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
include Redisable
|
||||
include Lockable
|
||||
|
||||
def call(status, activity_json, object_json, request_id: nil)
|
||||
def call(status, activity_json, object_json, request_id: nil, activity_account_id: nil)
|
||||
raise ArgumentError, 'Status has unsaved changes' if status.changed?
|
||||
|
||||
@activity_json = activity_json
|
||||
|
@ -17,6 +17,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
@media_attachments_changed = false
|
||||
@poll_changed = false
|
||||
@request_id = request_id
|
||||
@activity_account_id = activity_account_id
|
||||
|
||||
# Only native types can be updated at the moment
|
||||
return @status if !expected_type? || already_updated_more_recently?
|
||||
|
@ -251,7 +252,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
return unless significant_changes?
|
||||
|
||||
@previous_edit&.save!
|
||||
@status.snapshot!(account_id: @account.id, rate_limit: false)
|
||||
@status.snapshot!(account_id: editor_account_id, rate_limit: false)
|
||||
end
|
||||
|
||||
def editor_account_id
|
||||
@activity_account_id || @account.id
|
||||
end
|
||||
|
||||
def skip_download?
|
||||
|
|
|
@ -115,5 +115,58 @@ RSpec.describe ActivityPub::Activity::Update do
|
|||
expect(status.edited_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a Note object' do
|
||||
let!(:status) { Fabricate(:status, uri: 'https://example.com/statuses', text: 'Foo', account: sender) }
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Update',
|
||||
actor: sender.uri,
|
||||
object: {
|
||||
type: 'Note',
|
||||
id: status.uri,
|
||||
attributedTo: status.account.uri,
|
||||
content: 'Bar',
|
||||
published: '2022-01-22T15:00:00Z',
|
||||
updated: '2022-01-22T16:00:00Z',
|
||||
},
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
status.update!(uri: ActivityPub::TagManager.instance.uri_for(status))
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'updates the status' do
|
||||
expect(status.reload.text).to eq('Bar')
|
||||
end
|
||||
|
||||
context 'when the activity actor and object atttributedTo are different' do
|
||||
let!(:another_actor) { Fabricate(:account) }
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Update',
|
||||
actor: another_actor.uri,
|
||||
object: {
|
||||
type: 'Note',
|
||||
id: status.uri,
|
||||
attributedTo: status.account.uri,
|
||||
content: 'Bar',
|
||||
published: '2022-01-22T15:00:00Z',
|
||||
updated: '2022-01-22T16:00:00Z',
|
||||
},
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it 'updates the status' do
|
||||
expect(status.reload.text).to eq('Bar')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -463,5 +463,23 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
|||
subject.call(status, json, json)
|
||||
expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC'
|
||||
end
|
||||
|
||||
context 'with an activity_account_id' do
|
||||
let(:activity_account) { Fabricate(:account) }
|
||||
|
||||
it 'creates edits with the right editor' do
|
||||
allow(DistributionWorker).to receive(:perform_async)
|
||||
subject.call(status, json, json, activity_account_id: activity_account.id)
|
||||
expect(status.edits.reload.last.account_id).to eq activity_account.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an activity_account_id' do
|
||||
it 'creates edits with the right editor' do
|
||||
allow(DistributionWorker).to receive(:perform_async)
|
||||
subject.call(status, json, json)
|
||||
expect(status.edits.reload.last.account_id).to eq status.account.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue